2017-04-15 120 views
0

比方说,我有这样的:如何使用Python 3从html标签样式获取内容?

<bgi align="br" bgalp="100" bgc="ccffff" hasrec="0" ialp="49" isvid="1" tile="0" useimg="1"/> 

我只是想采取“CCFFFF”从BGC,但不知道如何,因为这些信息变化做到这一点。试图与re.compile,但我在这个真正的新...

+0

[美丽的汤](https://www.crummy.com/software/BeautifulSoup/)很适合这个 – davedwards

回答

0

一种选择是使用BeautifulSoup,并调用'bgc'属性'bgi'标签:

from bs4 import BeautifulSoup 

html_doc = """<bgi align="br" bgalp="100" bgc="ccffff" hasrec="0" ialp="49" isvid="1" tile="0" useimg="1"/>""" 

soup = BeautifulSoup(html_doc, 'html.parser') 

print(soup.bgi['bgc']) 

输出:

ccffff 
+0

它的工作! ^^非常感谢你 – Shiroe

+0

对,很高兴帮助!欢迎 – davedwards