python3 使用正则表达式匹配ajax文本数据

首先正则表达式要匹配字典前的数据
 

myre = re.compile(r'var jsonm = (.*?);')

如果多匹配数据,则无法使用json数据类型
 

myre = re.compile(r'var jsonm = {"stat":200,"musiclist":\[(.+)],"')

用以上正则匹配后报错内容:

json.decoder.JSONDecodeError: Extra data: line 1 column 463 (char 462)

 匹配全文数据:

data = myre.findall(res.text)

匹配完的数据是一个列表,通过【0】取值,数据是STR类型,使用json.loads()转成 json类型

猜你喜欢

转载自blog.csdn.net/qq_42142258/article/details/82783249