gpt4 book ai didi

python - 用于读取标签 Python 的正则表达式

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

我想用正则表达式读取标签中的元素,例如:

<td>Stuff Here</td>
<td>stuff
</td>

我正在使用以下内容:re.findall(re.compile('<td>(.*)</td>'), str(line).strip())

我怎么能读到第一个<td>标记,但不是第二个?

最佳答案

对于一般情况,您can't use regular expressions for parsing markup .你能做的最好的事情就是开始使用 HTML 解析器,有很多 good options在那里,恕我直言Beautiful Soup是一个不错的选择。

关于python - 用于读取标签 Python 的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17135205/

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