[英]How can I find string with regular expressions in Python
I have html string like that for example例如,我有这样的 html 字符串
<td align="left" nowrap="nowrap">John 23</td>
I want to find "John 23" between '<td align="left" nowrap="nowrap">'
and '</td>'
我想在'<td align="left" nowrap="nowrap">'
和'</td>'
之间找到“John 23”
I want to find with Regular Expressions in python我想在 python 中使用正则表达式查找
How can I do it?我该怎么做?
Use BeautifulSoup to parse HTML.使用 BeautifulSoup 解析 HTML。 Regex is the wrong tool;正则表达式是错误的工具; it works fine for this example but wouldn't scale well to a full document.它适用于这个例子,但不能很好地扩展到一个完整的文档。
>>> from bs4 import BeautifulSoup
>>> html = '<td align="left" nowrap="nowrap">John 23</td>'
>>> BeautifulSoup(html).find("td").text
'John 23'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.