Skip to content

Instantly share code, notes, and snippets.

@utkarshmalik211
Created February 8, 2016 13:47
Show Gist options
  • Save utkarshmalik211/f1aabe4bbe38d81275fd to your computer and use it in GitHub Desktop.
Save utkarshmalik211/f1aabe4bbe38d81275fd to your computer and use it in GitHub Desktop.
Python script to scrape a given amazon page and list all the prices with item names (Basicaly for books)
from bs4 import BeautifulSoup
from urllib.request import urlopen
import re
try:
html=urlopen("http://www.amazon.in/b/ref=BizStrategy?_encoding=UTF8&node=1318070031&pf_rd_m=A1VBAL9TL5WCBF&pf_rd_s=merchandised-search-4&pf_rd_r=175CVN4B0C6BS94WK9BH&pf_rd_t=101&pf_rd_p=799588247&pf_rd_i=976389031").read()
except:
print("Connection Error")
else:
bsobj=BeautifulSoup(html,"html.parser")
for tag in bsobj.findAll('h2',{"class":"a-size-medium a-color-null s-inline s-access-title a-text-normal"}):
print(tag.get_text())
try:
a=tag.find_next('a',{"title":"Kindle Edition"}).find_next('span',{"class":"a-size-base a-color-price s-price a-text-bold"}).get_text()
except:
print("Not availaible in kindle")
else:
print("Kindle price :",a)
try:
b=tag.find_next('a',{"title":"Paperback"}).find_next('span',{"class":"a-size-base a-color-price s-price a-text-bold"}).get_text()
except:
print("Price of paperback was'nt scraped")
else:
print("Paperback price :",b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment