使用 beautiful soup 基于类和 href 标签解析 html 标签
我正在尝试使用 BeautifulSoup 解析 HTML。
我想要的内容是这样的:
<a class="yil-biz-ttl" id="yil_biz_ttl-2" href="http://some-web-url/" title="some title">Title</a>
我尝试并得到以下错误:
maxx = soup.findAll("href", {"class: "yil-biz-ttl"})
------------------------------------------------------------
File "<ipython console>", line 1
maxx = soup.findAll("href", {"class: "yil-biz-ttl"})
^
SyntaxError: invalid syntax
我想要的是字符串:http://some-web-url/
I am trying to parse HTML with BeautifulSoup.
The content I want is like this:
<a class="yil-biz-ttl" id="yil_biz_ttl-2" href="http://some-web-url/" title="some title">Title</a>
i tried and got the following error:
maxx = soup.findAll("href", {"class: "yil-biz-ttl"})
------------------------------------------------------------
File "<ipython console>", line 1
maxx = soup.findAll("href", {"class: "yil-biz-ttl"})
^
SyntaxError: invalid syntax
what i want is the string : http://some-web-url/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要查找所有此类链接:
To find all such links:
您在
"class
之后缺少一个闭引号:也应该
如此,我认为您不能像这样搜索
href
这样的属性,我认为您需要搜索标签:You're missing a close-quote after
"class
:should be
also, I don't think you can search for an attribute like
href
like that, I think you need to search for a tag:要查找 CSS 类
"yil-biz-ttl"
中具有href
属性(其中包含任何内容)的所有元素:
目前所有其他答案都不满足上述要求。
To find all
<a/>
elements from CSS class"yil-biz-ttl"
that havehref
attribute with anything in it:At the moment all other answers don't satisfy the above requirements.
好吧,首先你有一个语法错误。您在
class
部分的引用错误。尝试:
maxx = soup.findAll("href", {"class": "yil-biz-ttl"})
Well first of all you have a syntax error. You have your quotes wrong in
class
part.Try:
maxx = soup.findAll("href", {"class": "yil-biz-ttl"})