【发布时间】:2016-08-21 03:57:49
【问题描述】:
以下是我的资料:
输入:
\"button\" \"button\" href=\"#\" data-id=\"11111111111\" \"button\" \"button\" href=\"#\" data-id=\"222222222222\"
\"button\" \"button\" href=\"#\"
我想要的输出:
11111111111
222222222222
我的第一个运行良好的代码:
text = 'data-id=\"11111111111 \" data-id=\"222222222222\" '
c = re.findall('data-id=\\"(.*?)\\"', text)
我的第二个代码不起作用。什么都不显示
with open("E:/test.txt","r") as f:
text = f.readline()
c = re.findall('data-id=\\"(.*?)\\"', text)
为什么我的辅助代码不起作用。请帮我修复它。我非常感谢你。谢谢你:)
【问题讨论】:
-
如果你想让它工作,你的缩进是错误的。
-
这种输入是从哪里来的?它真的看起来像 HTML 风格。
-
请查看我的回答,了解为什么您的第一个代码有效但第二个无效。