# -*- coding: utf-8 -*-
"""
Created on Fri Dec 16 08:05:42 2015
@python_version Python3

@context: MaGIC Analytics 
@prof: goh.yongkheng_at_gmail.com
@author: chejoharia

@purpose: WebScraping Excercise
@         - Extract Lazada Daily Top 110 top sellers
@input      : http://www.lazada.com.my/highlights-top-sellers/?page=1'	
@output     : a tab delimted dataset in txt file of today's 110 top selling items
"""


@@ -408,8 +408,812 @@
 ms%0A%22%22%22%0A%0A
+############################################################%0A#%0A# Using Python3%0A# python3 ./WebScrapLazadaTop110Sells.py%0A#%0A############################################################%0A%0Aimport time%0Aimport io%0Afrom urllib.request import urlopen%0Afrom bs4 import BeautifulSoup%0A%0A%0A############################################################%0A#%0A# Prepare a tab delimited file to store the data%0A#%0A############################################################%0A%0A# date in YYYYMMDD format%0A# append date to filename%0Afilename = 'Lazada_Top_Sellers' + time.strftime('%25Y%25m%25d') + '.txt'%0A%0A# use io.open() to avoid Unicode%0Af = io.open(filename,'w', encoding='utf8')%0A%0A# write variable names%0Af.write('day-ranking'%0A%09+'%5Ct'+'product-sku'%0A%09+'%5Ct'+'product-name'%0A%09+'%5Ct'+'price-normal'%0A%09+'%5Ct'+'price-discount'%0A%09+'%5Ct'+'discount'+'%5Cn')%0A

read url and create empty output file