python自用编码转换
作者:互联网
import requests
import json
import re
def result_value_replace(result_value):
#数字匹配不上返回-1
try:
non_decimal = re.compile(r'[^\d.]+')
result_value = non_decimal.sub('', result_value)
return float(result_value)
except Exception:
return -1
def GetName(url):
resp=requests.get(url);
# text是获取文本,resp.json是获取json
return resp.text;
# a=open('C:\\Users\\10351\\Desktop\\abc.txt','r',encoding='utf-8')
# print(json.dumps(json.load(a),ensure_ascii=False))
#获取页面编码
reponse = requests.get("https://img1.maka.im/user/9784633/template/T_QLS8FEHW/request/T_QLS8FEHW_sv3.json?time=2020020116")
encoding = requests.utils.get_encodings_from_content(reponse.text)
if not encoding:
encoding = reponse.apparent_encoding
content = reponse.content.decode(encoding)
content = json.loads(content)
print(json.dumps(content,ensure_ascii=False))
# reponse = requests.get("http://img1.maka.im/user/11450527/event/C46M4PQQW11450527/C46M4PQQW11450527_v11.json")
# reponse = requests.get("https://img1.maka.im/user/9784633/template/T_QLS8FEHW/request/T_QLS8FEHW_sv3.json?time=2020020116")
# print(reponse.json())
# print(json.dumps(reponse.text()))
#总站所有报告
# url="https://3g.dxy.cn/newh5/view/pneumonia_timeline?whichFrom=dxy"
# pattern = re.compile(r'id ="getTimelineServervice"')
# object_match=pattern.match(GetName(url))
# rs=object_match.group(0)
# print(result_value_replace('18-20'))
我要用代码向我喜欢的女孩表白 发布了105 篇原创文章 · 获赞 23 · 访问量 1万+ 私信 关注
标签:编码,encoding,python,reponse,content,json,自用,result,requests 来源: https://blog.csdn.net/qq_38403590/article/details/104145651