【发布时间】:2019-08-12 13:31:58
【问题描述】:
每当我尝试运行此代码时:
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 = price[0:7]
if (converted_price < '₹ 1,200'):
send_mail()
print(converted_price)
print(title.strip())
if(converted_price > '₹ 1,400'):
send_mail()
它给了我一个错误AttributeError: 'NoneType' object has no attribute 'get_text' 之前这段代码工作正常。
【问题讨论】:
-
UI 可能会发生变化。 ID:
priceblock_ourprice可能不再在新 UI 中可用。 -
soup.find(id="productTitle")或soup.find(id="priceblock_ourprice")返回None
标签: python