Kyxrecon

Simpleamazoneprice.py

Apr 22nd, 2017
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #How to make Simple AMAZONE web scraping using Python ?
  2. #TUTORIAL by Kyxrec0n
  3.  
  4. # You need to import BeautifulSoup from bs4 with...
  5. from bs4 import BeautifulSoup
  6. from urllib2 import Request, urlopen
  7. import decimal
  8.  
  9.  
  10. #URL test : http://www.amazon.com/Introduction-Algorithms-3rd-Thomas-Cormen/dp/0262033844
  11.  
  12. def findPrice(url, selector):
  13. userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"
  14. req = Request(url, None, {'User-Agent': userAgent})
  15. html = urlopen(req).read()
  16. soup = BeautifulSoup(html, "lxml")
  17. return decimal.Decimal(soup.select(selector)[0].contents[0].strip().strip("$"))
  18.  
  19. print findPrice("http://www.amazon.com/Introduction-Algorithms-3rd-Thomas-Cormen/dp/0262033844", "#newOfferAccordionRow .header-price")
Advertisement
Add Comment
Please, Sign In to add comment