File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
Amazon Best Sellers Scraper Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change 11import requests
22from bs4 import BeautifulSoup
33
4+
45def scrape_amazon_bestsellers (category_url ):
56 headers = {
67 "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3" }
@@ -11,13 +12,15 @@ def scrape_amazon_bestsellers(category_url):
1112 products = soup .find_all ('div' , class_ = 'zg-item-immersion' )
1213
1314 for index , product in enumerate (products , start = 1 ):
14- title = product .find ('div' , class_ = 'p13n-sc-truncate' ).get_text ().strip ()
15+ title = product .find (
16+ 'div' , class_ = 'p13n-sc-truncate' ).get_text ().strip ()
1517 rank = index
1618 print (f"Rank: { rank } \n Title: { title } \n " )
1719
1820 else :
1921 print ("Failed to retrieve data from Amazon." )
2022
23+
2124if __name__ == "__main__" :
2225 category_url = "https://www.amazon.com/Best-Sellers-Electronics/zgbs/electronics/"
2326 scrape_amazon_bestsellers (category_url )
You can’t perform that action at this time.
0 commit comments