2024-10-08 19:24:03 发布
网友
我试图在div类下提取信息,但是当我使用代码时,消息显示“div”未定义。汤做得很好,我看到旁边有很多小酒鬼,有什么问题吗?你知道吗
soup = BeautifulSoup(html, "html.parser") for item in soup.find_all("div", attrs={"class" : "article-content"}): print(div.find("a")['href'])
div变量实际上从未定义,您的意思是使用item:
div
item
for item in soup.find_all("div", attrs={"class" : "article-content"}): print(item.find("a")['href']) # or item.a['href']
或者,您可以通过CSS selector直接访问链接:
for a in soup.select("div.article-content a"): print(a['href'])
div
变量实际上从未定义,您的意思是使用item
:或者,您可以通过CSS selector直接访问链接:
相关问题 更多 >
编程相关推荐