在python搜索html源代码的regex findall语句中使用“in”时遇到了一个问题。你知道吗
我正在搜索一些html源代码,似乎无法在findall语句中使用引号(“)。由于某些无法更改的要求,我无法使用像beautifulsoup这样的外部库来帮助搜索。我已将变量名更改为搜索。你知道吗
from re import *
def suncorp_find():
# Setup to find information
suncorp_file = open('suncorp.html')
contents_suncorp = suncorp_file.read()
# Search the HTMl files to find the data
suncorp_titles = findall(r"\"event-title\">(\w )+", contents_suncorp)
print(suncorp_titles)
suncorp_find()
我希望得到一个列表中的项目,但我只是得到一个空列表。当只搜索事件标题时,我得到多个带有搜索标题列表的项目。你知道吗
提前谢谢你的帮助
<h6 class="event-title">Queensland Reds v Jaguares</h6>
你应该引用
"
符号。你知道吗输出:
另外,我建议您使用regex test website来验证您的表达式。你知道吗
使用此正则表达式:
或者为什么不低于??我已删除
\w
检查。我不知道你是否真的需要它。你知道吗我接受了意见:
输出:
相关问题 更多 >
编程相关推荐