Advertisement
furas

Python - ebay

May 12th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import bs4, requests
  2.  
  3. def ebay(search):
  4.    
  5.     res = requests.get('http://www.ebay.in/sch/i.html?_from=R40&_trksid=p2050601.m570.l1313.TR11.TRC1.A0.H0.Xraspberry+pi.TRS0&_nkw=%s&_sacat=0' % search)
  6.     home_page_object = bs4.BeautifulSoup(res.text, "html.parser")
  7.     elements = home_page_object.find_all("li", {"class" : "sresult lvresult clearfix li"})
  8.  
  9.     name = []
  10.     price = []
  11.     link = []
  12.  
  13.     for e in elements:
  14.         item_name = e.select("a")[1]
  15.         item_price = e.select("span")[0]
  16.         item_link = e.select("a")[1]
  17.  
  18.         if item_name.contents[0] != "\n" and len(item_price.contents) == 3:
  19.             name.append(item_name.contents[0])
  20.             price.append(item_price.contents[2])
  21.             link.append(item_link["href"])
  22.    
  23.     for n, p, l in zip(name, price, link):
  24.         print(n, ":", p, ":", l)
  25.  
  26. ebay("raspberry pi")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement