这是我的代码:
from bs4 import BeautifulSoup
import requests
import smtplib
URL = 'https://www.amazon.com/Garmin-Forerunner-Contactless-Payments-Wrist-Based/dp/B07DPMQ59K?ref_=Oct_DLandingS_D_503e89e0_61&smid=ATVPDKIKX0DER'
headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36 OPR/68.0.3618.112'}
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, "html.parser")
title = soup.find(id="prodcutTitle").get_title()
print(title)
为什么总是出现此错误?有人可以帮我吗?
Lagis_YT YT
The Issue in this,
title = soup.find(id="prodcutTitle").get_title()
where this is not any objectsoup.find(id="prodcutTitle")
with which you can call any method and retrive the data.instead of you get the some string content.您必须更改基于对象的调用方法。
谢谢
拉吉斯。 在您的代码中,他们曾写过一个小的拼写错误-
您已经写了prodcutTitle,而它应该是productTitle。
我什至通过使用该页面上的JS控制台进行了检查。
您可以在Google上找到更多信息