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 1
1
import requests
2
2
from bs4 import BeautifulSoup
3
3
4
+
4
5
def scrape_amazon_bestsellers (category_url ):
5
6
headers = {
6
7
"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):
11
12
products = soup .find_all ('div' , class_ = 'zg-item-immersion' )
12
13
13
14
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 ()
15
17
rank = index
16
18
print (f"Rank: { rank } \n Title: { title } \n " )
17
19
18
20
else :
19
21
print ("Failed to retrieve data from Amazon." )
20
22
23
+
21
24
if __name__ == "__main__" :
22
25
category_url = "https://www.amazon.com/Best-Sellers-Electronics/zgbs/electronics/"
23
26
scrape_amazon_bestsellers (category_url )
You can’t perform that action at this time.
0 commit comments