akr*_*nov 2 html python regex parsing
如何<b>使用正则表达式在Python中获取嵌套HTML标记的值?
<a href="/model.xml?hid=90971&modelid=4636873&show-uid=678650012772883921" class="b-offers__name"><b>LG</b> X110</a>
# => LG X110
Run Code Online (Sandbox Code Playgroud)
不要使用正则表达式来解析HTML.使用像BeautifulSoup这样的HTML解析器.看看它有多容易:
from BeautifulSoup import BeautifulSoup
html = r'<a href="removed because it was too long"><b>LG</b> X110</a>'
soup = BeautifulSoup(html)
print ''.join(soup.findAll(text=True))
# LG X110
Run Code Online (Sandbox Code Playgroud)