【发布时间】:2019-09-04 21:32:54
【问题描述】:
因此,我编写了一段代码,用于获取有关亚马逊产品的信息,并且可以获取价格并设置条件。如果满足价格条件,我将使用 gmail 发送消息到我自己。问题是当我使用代码得到它说的价格时
'NoneType' object has no attribute 'get_text'
这是我的代码。不是它的全部部分,而只是收集有关产品的信息:
url="https://www.amazon.de/Sony-DigitalKamera-Touch-Display-Vollformatsensor-KartenSlots/dp/B07B4L1PQ8/ref=sr_1_3?keywords=sony+a7&qid=1561393494&s=gateway&sr=8-3"
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 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:6])
print(converted_price)
print(title.strip())
【问题讨论】:
-
你能检查
soup的内容来验证它是你期望的html吗? -
是的,我检查了它是我期待的 html
-
请edit您的问题并将错误的填充回溯添加到它。
-
根据您的错误,这意味着
soup无法找到 id 等于“priceblock_ourprice”的元素
标签: python beautifulsoup