我想用正则表达式读取标签中的元素,例如:
<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/