注册 登录
编程论坛 Python论坛

求助帖:获取js里的变量

uwei 发布于 2019-09-05 09:45, 1170 次点击
var now="https://baidu.com-ok-baidu.com/share/524e30e771dba8110c0241a0882023d0";var pn="kuyun"; var next="";var prePage="/play/55638-1-0.html";var nextPage="/play/55638-1-0.html";

我想拿到now的值,应该怎么弄?
1 回复
#2
fall_bernana2019-09-05 16:54
回复 楼主 uwei
程序代码:

import re
a="""var now="https://baidu.com-ok-baidu.com/share/524e30e771dba8110c0241a0882023d0";var pn="kuyun"; var next="";var prePage="/play/55638-1-0.html";var nextPage="/play/55638-1-0.html";"""
print(a)
s=re.findall(r'var (?P<name>\w+)=\"(?P<value>[^\"]+)\"',a)
print(s)
[('now', 'https://baidu.com-ok-baidu.com/share/524e30e771dba8110c0241a0882023d0'), ('pn', 'kuyun'), ('prePage', '/play/55638-1-0.html'), ('nextPage',
'/play/55638-1-0.html')]
1