Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #How to make Simple AMAZONE web scraping using Python ?
- #TUTORIAL by Kyxrec0n
- # You need to import BeautifulSoup from bs4 with...
- from bs4 import BeautifulSoup
- from urllib2 import Request, urlopen
- import decimal
- #URL test : http://www.amazon.com/Introduction-Algorithms-3rd-Thomas-Cormen/dp/0262033844
- def findPrice(url, selector):
- userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"
- req = Request(url, None, {'User-Agent': userAgent})
- html = urlopen(req).read()
- soup = BeautifulSoup(html, "lxml")
- return decimal.Decimal(soup.select(selector)[0].contents[0].strip().strip("$"))
- 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