我需要使用python脚本(2.7)从远程页面中提取包含多行JSON的javascript变量,我希望使用regex来实现这一点,但是我的模式不返回任何内容。
我做错什么了?
这是我的密码:
request = urllib2.Request("http://somesite.com/affiliates/")
result = urllib2.urlopen(request)
affiliates = re.findall('#var affiliates = (.*?);\s*$#m', result.read())
print affiliates发布于 2013-07-25 12:14:20
如果您查看re.findall(pattern, string, flags=0)的文档,就会发现您需要改变使用它的方式
affiliates = re.findall('var affiliates = (.*?);\s*$', result.read(), re.M)您还可能需要考虑如何在JavaScript中使用空白。
https://stackoverflow.com/questions/17857613
复制相似问题