【发布时间】:2019-05-24 12:04:29
【问题描述】:
在 python 搜索 html 源代码的正则表达式 findall 语句中,我遇到了使用 " 的问题。
我正在搜索一些 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()
我希望得到一个包含项目的列表,但我只是得到一个空列表。仅搜索 event-title 时,我会使用 search_titles 列表获得多个项目。
提前感谢您的帮助
<h6 class="event-title">Queensland Reds v Jaguares</h6>
【问题讨论】:
-
样本输入是什么?
-
尝试引用符号:
\\"event-title\\">([\w ]+) -
我已经添加了指向 html 源代码的链接,我也尝试了引用符号,但也没有用
-
请在问题本身和纯文本中包含示例输入;不在图像的链接中。还包括您的预期输出。
-
使用给定的样本输入,我得到
['Queensland Reds v Jaguares']。这不是你要找的吗?