Created
December 15, 2021 05:22
-
-
Save shahidcsebd/d07dd7de7f3254f8d99023fc0a6a79b8 to your computer and use it in GitHub Desktop.
Search on Amazon with a Keyword and Get the Result Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
search_keyword = input("Write a keyword to search on Amazon: ") | |
search_format = search_keyword.strip().replace(' ', '+') | |
make_url = 'https://www.amazon.com/s?k=' + search_format | |
print(make_url) | |
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", "Referer": "https://www.amazon.com/"} | |
response = requests.get(make_url, headers=headers) | |
soup = BeautifulSoup(response.text, 'html.parser') | |
# Print the nicely formatted source code | |
print(soup.prettify()) | |
links = soup.findAll('a') | |
# Print All links in the amazon SERP | |
for link in links: | |
print(link.get('href')) | |
# Now I need to scrap the first 10 product URLs from this soup. Please help... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment