Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cd20865

Browse files
Merge pull request #2942 from avinashkranjan/deepsource-transform-f7175235
format code with autopep8
2 parents a16021e + 4fa8c63 commit cd20865

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

‎Amazon Best Sellers Scraper/script.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22
from bs4 import BeautifulSoup
33

4+
45
def 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}\nTitle: {title}\n")
1719

1820
else:
1921
print("Failed to retrieve data from Amazon.")
2022

23+
2124
if __name__ == "__main__":
2225
category_url = "https://www.amazon.com/Best-Sellers-Electronics/zgbs/electronics/"
2326
scrape_amazon_bestsellers(category_url)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /