以下是一个示例,使用Python的Requests和BeautifulSoup模块获取亚马逊商品信息。
import requests
from bs4 import BeautifulSoup
url = "https://www.amazon.com/dp/B01J94SWWU" # 商品详情页面链接
headers = {'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'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
title = soup.find('span', {'id': 'productTitle'}).text.strip()
price = soup.find('span', {'id': 'priceblock_ourprice'}).text.strip()
rating = soup.find('span', {'class': 'a-icon-alt'}).text.strip()
print("Title:", title)
print("Price:", price)
print("Rating:", rating)
注意,要使此代码正常运行,需要将链接中的商品ID替换为具体商品的ID。同时,还需要安装和引入Requests和 BeautifulSoup模块。
如果不会请联系作者有封装好的api直接使用。