python BeautifulSoup搜索标签 [英] python BeautifulSoup searching a tag

查看:97
本文介绍了python BeautifulSoup搜索标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里的第一篇文章,我试图在此特定的html中找到所有标签,但我无法将它们删除,这是代码:

My first post here, I'm trying to find all tags in this specific html and i can't get them out, this is the code:

from bs4 import BeautifulSoup
from urllib import urlopen

url = "http://www.jutarnji.hr"
html_doc = urlopen(url).read()
soup = BeautifulSoup(html_doc)
soup.prettify()
soup.find_all("a", {"class":"black"})

查找函数返回[],但是我发现html中有类为"black"的标签,我会错过吗?

find function returns [], but i see that there are tags with class:"black" in the html, do I miss something?

谢谢, 韦德兰

推荐答案

我也遇到了同样的问题.

I also had same problem.

尝试

soup.findAll("a",{"class":"black"})

代替

soup.find_all("a",{"class":"black"})

soup.findAll()对我来说很好.

soup.findAll() works well for me.

这篇关于python BeautifulSoup搜索标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆