Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Last active November 4, 2020 13:05
Show Gist options
  • Save Abhayparashar31/50be2254fde7e05f3f6a4e29f5d9b86d to your computer and use it in GitHub Desktop.
Save Abhayparashar31/50be2254fde7e05f3f6a4e29f5d9b86d to your computer and use it in GitHub Desktop.
def amazon(book,num):
book = book.replace(" ",'+')
for i in range(num):
url = f'https://www.amazon.in/s?k={book}&page={num}&qid=1599544528&ref=sr_pg_{num}'
res = requests.get(url,headers=headers)
soup = BeautifulSoup(res.text,'html.parser')
names = soup.select(".a-size-medium")
for i in range(len(names)):
lst = []
try:
price = soup.select(".a-spacing-top-small .a-price-whole")[i].get_text().strip()
if price != "":
names = soup.select(".a-color-base.a-text-normal")[i].get_text().strip()
link = soup.select("h2 .a-link-normal")[i].attrs.get("href")
link = "https://www.amazon.in/"+str(link)
except:
price = ""
names = ""
amazon(input("Enter the book name\n"),int(input("Number of pages")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment