import requests
url='https://accounts.douban.com'
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'}
cookies_str ='此处为用工具所获得的cookie值'
cookies = {}
for line in cookies_str.split(';'):
key,value = line.split('=',1)
cookies[key] =value
response = requests.get(url=url,cookies= cookies,headers= headers)
print(response.status_code)
pycharm运行后报两个错如下图:
1.equests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
2.requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
解决问题1:
import os
os.environ['NO_PROXY'] = 'https://accounts.douban.com'
解决问题2:
response= requests.get(url=url,cookies= cookies,headers= headers,verify=False)
最终代码为:
import requests
import os
os.environ['NO_PROXY'] ='https://accounts.douban.com'
url ='https://accounts.douban.com'
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'}
cookies_str ='此处为用工具所获得的cookie值'
cookies = {}
for line in cookies_str.split(';'):
key,value = line.split('=',1)
cookies[key] =value
response = requests.get(url=url,cookies= cookies,headers= headers,verify=False)
print(response.status_code)