We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents a16021e + 4fa8c63 commit cd20865Copy full SHA for cd20865
Amazon Best Sellers Scraper/script.py
@@ -1,6 +1,7 @@
1
import requests
2
from bs4 import BeautifulSoup
3
4
+
5
def scrape_amazon_bestsellers(category_url):
6
headers = {
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')
13
14
for index, product in enumerate(products, start=1):
- title = product.find('div', class_='p13n-sc-truncate').get_text().strip()
15
+ title = product.find(
16
+ 'div', class_='p13n-sc-truncate').get_text().strip()
17
rank = index
18
print(f"Rank: {rank}\nTitle: {title}\n")
19
20
else:
21
print("Failed to retrieve data from Amazon.")
22
23
24
if __name__ == "__main__":
25
category_url = "https://www.amazon.com/Best-Sellers-Electronics/zgbs/electronics/"
26
scrape_amazon_bestsellers(category_url)
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments