猿问

Python:re.findall 不会在 html 中找到字符串

re.findall 不会在 html 中找到字符串。这是我的代码:


def get_id(html_source):

    the_button = re.findall("preview.aspx?id=1692003076", html_source)

    print(the_button)

当我print(html_source)得到 html 时,可以看到它包含“preview.aspx?id=1692003076”。re.search 也未能找到该字符串。


我的代码中有另一个 re.findall ,它工作正常:


id_matches = re.findall('<input type="checkbox" id="\d+"', html_source)

知道为什么它不起作用吗?


郎朗坤
浏览 252回答 1
1回答

千万里不及你

注意“?”&nbsp;是正则表达式中的特殊字符。你需要逃避它。
随时随地看视频慕课网APP

相关分类

Python
我要回答