解决办法是
import requests,json,time
requests.packages.urllib3.disable_warnings()
requests.adapters.DEFAULT_RETRIES = 5 #增加重连次数
def get_price(url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36',
'Referer': 'https://www.baidu.com',
}
s = requests.session()
s.keep_alive = False # 关闭多余连接
response = s.get(url=url,headers=headers,verify=False)
text_0 = response.text[14:-1]
try:
text = json.loads(text_0,strict=False)
except Exception as e:
print(e)
print(text_0)
print(text)
return
# print(text)
return text