【发布时间】:2021-01-01 09:59:46
【问题描述】:
我正在运行 YouTube 教程中的以下代码,但是当我想从 .totalcount 类中获取文本时,我收到了 NoneType Object has no attribute "text" 错误。
事实上,在教程视频中它起作用了。有什么帮助吗?如果在细节上会很棒。提前致谢。
url = "https://newyork.craigslist.org/"
site = requests.get(url)
soup = BeautifulSoup(site.text, "html.parser")
sub_link = soup.select("#jjj0 a")
for l in sub_link:
jobcat = l.text
joburl = "https://newyork.craigslist.org/" + l.get("href")
#print(joburl)
r = requests.get(joburl)
soup2 = BeautifulSoup(r.text, "html.parser")
#for total in soup2.select_one("span", class_ = "totalcount"):
#print(total)
total = soup2.select_one(".totalcount").text
#total = soup2.find("span", class_ = "totalcount").text.strip()
print(total)
【问题讨论】:
标签: python beautifulsoup python-requests