Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. import bs4, requests
  2.  
  3. def getAmazonPrice(productUrl):
  4.         req = requests.get(productUrl)
  5.            
  6.         try:
  7.                 req.raise_for_status()
  8.         except:
  9.                 return None
  10.  
  11.         soup = bs4.BeautifulSoup(req.text,'html.parser')
  12.         elem = soup.select('#unqualifiedBuyBox > div:nth-of-type(1) > div:nth-of-type(1) > span:nth-of-type(2)')
  13.         assert len(elem) >= 1
  14.  
  15.         return elem[0].text.strip()
  16.            
  17. price = getAmazonPrice('https://www.amazon.com.br/TABLET-SAMSUNG-TAB-T585-16GB/dp/B01G4618ZY/ref=sr_1_1?s=computers&ie=UTF8&qid=1516316045&sr=1-1')
  18.  
  19. print('The price is: '+price)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement