页面地址:view-source:http://yinyue.kuwo.cn/cinfo/24149/12_422038408_45/70%E5%90%8E.htm
如何使用python脚本获取上述页面中的jsonm变量;
# encoding: UTF-8
import urllib2
import re
import json
content = urllib2.urlopen('http://yinyue.kuwo.cn/cinfo/24149/12_422038408_45/70后.htm').read()
pattern = re.compile(r'var\s+jsonm[=\s]+((?:(?!stortData[=\s]+)[\s\S])*});[\s\S]*stortData')
result = pattern.findall(content)
result = result[0]
print result
s = json.loads(result)
print s
print s.keys()
print s["musiclist"][0]["name"]
import urllib2
import re
import json
content = urllib2.urlopen('http://yinyue.kuwo.cn/cinfo/24149/12_422038408_45/70后.htm').read()
pattern = re.compile(r'var\s+jsonm[=\s]+((?:(?!stortData[=\s]+)[\s\S])*});[\s\S]*stortData')
result = pattern.findall(content)
result = result[0]
print result
s = json.loads(result)
print s
print s.keys()
print s["musiclist"][0]["name"]
温馨提示:答案为网友推荐,仅供参考