Web Scraping Assignment Ebay
Web Scraping Assignment Ebay
Web scraping is a process of extracting valuable data from a website. You have to scrape a dataset from the retail link system to analyse the data. Find one
product in the retail link system and extract four attributes with at least ten records from the selected web pages. For example:
Website: Mudah.com
Product: iPhone
Send your Python codes by copying your codes into ms word. Send your data output in Microsoft Excel.
Website: Ebay
Attributes: Product Name, Product Price, Shipping Fee (free or not), Image
my_url = 'https://www.ebay.com.my/b/Accessories-for-Apple-Tablets-and-eReaders/176970/bn_826388'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup
page_soup.findAll('li',{'class':'s-item s-item--large'})
item
item[0]
item[0].findAll('div',{'class':'s-item__info clearfix'})
iteminfo[0]
iteminfo[0].a
iteminfo[0].a.h3
iteminfo[0].a.h3.getText().strip()
itemname = iteminfo[0].a.h3.getText().strip()
itemname
item[0].findAll('span',{'class':'s-item__price'})
itemprice = item[0].findAll('span',{'class':'s-item__price'})
itemprice[0]
itemprice[0].getText().strip()
price = itemprice[0].getText().strip()
item[0].findAll('span',{'class':'s-item__shipping s-item__logisticsCost'})
log[0]
log[0].getText().strip()
postage = log[0].getText().strip()
item[0].findAll('div',{'class':'s-item__image-wrapper'})
image = item[0].findAll('div',{'class':'s-item__image-wrapper'})
image[0]
image[0].img['src']
imagelink = image[0].img['src']
for i in item:
iteminfo = i.findAll('div',{'class':'s-item__info clearfix'})
itemname = iteminfo[0].a.h3.getText().strip()
print(itemname)
itemprice = i.findAll('span',{'class':'s-item__price'})
price = itemprice[0].getText().strip()
print(price)
postage = log[0].getText().strip()
print(postage)
imagelink = image[0].img['src']
print(imagelink)
filename='ebay.csv'
f=open(filename, 'w')
for i in item:
print(itemname)
f.write(itemname+',')
itemprice = i.findAll('span',{'class':'s-item__price'})
price = itemprice[0].getText().strip()
print(price)
f.write(price.replace(',','|')+',')
postage = log[0].getText().strip()
print(postage)
f.write(postage.replace(',','|')+',')
imagelink = image[0].img['src']
print(imagelink)
f.write(imagelink+'\n')
f.close()