[英]Python beautiful soup find content in class
I got a html like this: 我有这样的html:
<div class="row" data-keywordid="53707903">
<div class="kw-table-cell kw-keyword-name-cell">
</div>
</div>
In normal case i can take content inner of class "row" by using: soup.find("div",{"class": "row"})
but what i want is get the data-keywordid
and value of that 53707903
. 在正常情况下,我可以通过使用以下内容来获取类“ row”的内部内容: soup.find("div",{"class": "row"})
但是我想要的是获取该data-keywordid
53707903
的data-keywordid
53707903
和值。 I have no idea for it. 我不知道 Have anyway to get it? 反正有得到吗? Thanks ! 谢谢 !
from bs4 import BeautifulSoup
text = ''''
<div class="row" data-keywordid="53707903">
<div class="kw-table-cell kw-keyword-name-cell">
</div>
</div>
'''
soup = BeautifulSoup(text, "html.parser")
a = soup.find('div')
a.attrs['data-keywordid']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.