需要Python正则表达式帮助

anr*_*ots 1 python regex

我需要从一个网站上获取信息,并在<font color="red">needed-info-here</font>OR 之间<span style="font-weight:bold;">needed-info-here</span>随机输出.

我用的时候可以拿到它

start = '<font color="red">'
end = '</font>'
expression = start + '(.*?)' + end
match = re.compile(expression).search(web_source_code)
needed_info = match.group(1)
Run Code Online (Sandbox Code Playgroud)

,但后来我要挑获取要么<font>或者<span>,失败,当网站所使用的其他标记.

如何修改正则表达式以使其始终成功?

Kat*_*iel 7

不要使用正则表达式解析HTML.

正则表达式不是用于解决此问题的正确工具.查找BeautifulSouplxml.