Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Last active November 4, 2020 13:03
Show Gist options
  • Save Abhayparashar31/7fa409915cb1130708a8e4a157407b42 to your computer and use it in GitHub Desktop.
Save Abhayparashar31/7fa409915cb1130708a8e4a157407b42 to your computer and use it in GitHub Desktop.
def amazon(book):
book = book.replace(" ",'+')
url = f'https://www.amazon.in/s?k=python&ref=nb_sb_noss_2'
print(url)
res = requests.get(url,headers=headers)
soup = BeautifulSoup(res.text,'html.parser')
names = soup.select(".a-size-medium")
for i in range(len(names)):
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")
print("https://www.amazon.in/"+str(link))
print("\n")
except:
price = ""
names = ""
amazon(input("Enter the book name\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment