我刚刚开始了一个跟踪亚马逊价格的应用程序项目。根据教程视频,在这一步,当我运行代码时,它必须显示产品的名称和价格,但唯一出现的是下一个错误:AttributeError: 'NoneType' object has no attribute 'get_text'。我已经在其他页面上尝试过,并在这里修改了相同的主题,但没有找到答案。请帮忙 ;(
代码本身:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.amazon.es/dp/B07JQRWLXM/ref=nav_signin?pf_rd_r=FJX3CJC8RWFE3NPQJRNP&'
headers = {
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/86.0.4240.75 Safari/537.36'}
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()
converted_price = float(price[0:3])
print(converted_price)
print(title.strip())
UYOU
相关分类