gpt4 book ai didi

需要 Python 正则表达式帮助

转载 作者:太空宇宙 更新时间:2023-11-04 06:51:19 25 4
gpt4 key购买 nike

我需要从在 <font color="red">needed-info-here</font> 之间输出信息的网站获取信息或者 <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)

,但我必须选择获取 <font><span> ,失败,当网站使用其他标签时。

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

最佳答案

Don't parse HTML with regex.

Regex 不是解决此问题的正确工具。查找BeautifulSouplxml .

关于需要 Python 正则表达式帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3382552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com