正则表达式读取标签Python

Jam*_*len 2 html python regex tags

我想用regex读取标签内的元素,例如:

<td>Stuff Here</td>
<td>stuff 
</td>
Run Code Online (Sandbox Code Playgroud)

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

为什么我可以阅读第一个<td>标签,但不是第二个?

Ósc*_*pez 5

对于一般情况,您不能使用正则表达式来解析标记.你可以做的最好的事情是开始使用HTML解析器,有很多好的选择,恕我直言美丽的汤是一个不错的选择.