eval字符串str 转字典dict
str = '''
window.__ssr_data = JSON.parse("{"post_data":{"item_id":"7000687099049417735","uid":783275173879271,"ctime":1629974483,"type":"note"}
}");
'''
Info = re.search('<script>window.__ssr_data = JSON.parse("(.*?)");', result).group(1)
print("Info1=",Info)
Info = re.search('<script>window.__ssr_data = JSON.parse((.*?));', result).group(1)
print("Info2=",Info)
userInfo = (json.loads(eval(Info)))
print("userInfo1=",userInfo)
print("userInfo2=",type(userInfo))
返回结果:
Info1 = {"post_data":{"item_id":"7000687099049417735","uid":783275173879271,"ctime":1629974483,"type":"note"}}
Info2 = "{"post_data":{"item_id":"7000687099049417735","uid":783275173879271,"ctime":1629974483,"type":"note"}}"
返回结果:
userInfo1 = {"post_data":{"item_id":"7000687099049417735","uid":783275173879271,"ctime":1629974483,"type":"note"}}
userInfo2 = <class 'dict'>