from bs4 import BeautifulSoup
import requests
headers = {'Use-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/79.0.3945.130 Safari/537.36'}
url = 'https://www.amazon.com/Sony-Alpha-a6400-Mirrorless-Camera/dp/B07MV3P7M8/ref=sr_1_4?keywords=sony+alpha&qid=1581656953&s=electronics&sr=1-4'
page = requests.get(url,headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id="productTitle").get_text()
price = soup.find(id="priceblock_ourprice").get_text()
print(title)
print(price)
答案 0 :(得分:0)
您的代码工作正常,但在产品页面之前进行了机械手检查,因此您的请求在该机械手检查页面中查找span标签,但失败并返回None
。
以下链接可以为您提供帮助:python requests & beautifulsoup bot detection