2017-08-02 28 views
0

所以我有一个html文件,我想检查它的一些值。 例如:data-online =“false”,data-channel =“123breakmefree”如何检查html中的某些内容是否使用beautifulsoup设置为false或true?

所以我想检查'data-online'是否设置为true或false,以及在数据通道中标记了什么通道。如果频道是“123breakmefree”以外的其他内容。

谢谢!

P.S:英语不是我的主要语言,所以我找不到任何关于Google搜索的内容。

+2

请张贴一些代码,你已经尝试了。我们需要更具体的问题来帮助你。 – thaavik

+0

基本上是这样的:“https://github.com/tanelq/project/blob/master/twitchgdaget” –

+0

但它打印-1。因为某些原因。 –

回答

1

这段代码演示了如何加载HTML字符串,得到一个标记,然后属性:

from bs4 import BeautifulSoup 

html = '<div id="my-tag" data-online="false" data-channel="123breakmefree">test text</div>' 

s = BeautifulSoup(html) 
tag = s.find(id='my-tag') 

print tag.attrs 
print tag['data-online'] 
print tag['data-channel'] 
相关问题