以登录zhihu为例

方法1:手动构造RequestsCookieJar对象

手动登录zhihu后,从F12的network栏复制全部cookie出来赋值给cookies变量

cookies='_zap=01f158f1-ff75-438d-a8b3-cba055f449c1; d_c0="AICj1MstoA2PTkXzALxQcWePBFMeB7iJcjY=|1526867722"; q_c1=113a730a7a4c40d0bffd84d42a551489|1527563854000|1524791871000; Hm_lvt_ba7c84ce230944c13900faeba642b2b4=1527241782,1527563857,1527586103,1527743355; _xsrf=c92a1b0b-8efa-4ddf-b2b3-07cf5610b11c; l_n_c=1; l_cap_id="ZTc0MjgxYjYxMWNkNDUxMGFmMGQ5Y2ZlYmE2NDgxYmI=|1529994964|cae58c665907a32ef8d27ad74a51eca98fe4f97a"; r_cap_id="MTJjYmJmYjIzYTBhNGQ4MWIyZmQzZDZmNWJhNGY5Mjc=|1529994964|3d6f86e368a9f9ac5cb945f334656c07d408c613"; cap_id="ZWRiNzhhNjg3YjFhNDhiMWEyMGE4NGIyYWQ0M2E4YTQ=|1529994964|a48525f631fa3ace981207f6a748b9936f38ce73"; n_c=1; __utma=51854390.1837640810.1529994966.1529994966.1529994966.1; __utmc=51854390; __utmz=51854390.1529994966.1.1.utmcsr=zhihu.com|utmccn=(referral)|utmcmd=referral|utmcct=/; __utmv=51854390.000--|3=entry_date=20180427=1; tgw_l7_route=860ecf76daf7b83f5a2f2dc22dccf049; capsion_ticket="2|1:0|10:1529998680|14:capsion_ticket|44:MzI5NDI3NmY0ZDg2NDhlOGIwNTRhYzM1ODhlNTJiYTY=|177bd3ed5d98ccee8ca6b291d12240aaedaf6f1325fcb08457c912e4fbfeef46"; z_c0="2|1:0|10:1529998692|4:z_c0|92:Mi4xLVV3eUFBQUFBQUFBZ0tQVXl5MmdEU1lBQUFCZ0FsVk5aRHNmWEFCcmdPU2JNODdhYWgyM00tZ1oxT3l5dnRiMmp3|ccb1e3c59663aec502eddd76f154e65479fef3005490def7b35d8e2956a07b8a"'
headers={'host':'www.zhihu.com','User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36'}
jar=requests.cookies.RequestsCookieJar()
for cookie in cookies.split(';'):
    key,value=cookie.split('=',1)
    jar.set(key,value)
r=requests.get('https://www.zhihu.com',headers=headers,cookies=jar) 
print(r.text)

2.直接使用浏览器内的cookie

headers={'Cookie':'_zap=01f158f1-ff75-438d-a8b3-cba055f449c1; d_c0="AICj1MstoA2PTkXzALxQcWePBFMeB7iJcjY=|1526867722"; q_c1=113a730a7a4c40d0bffd84d42a551489|1527563854000|1524791871000; Hm_lvt_ba7c84ce230944c13900faeba642b2b4=1527241782,1527563857,1527586103,1527743355; _xsrf=c92a1b0b-8efa-4ddf-b2b3-07cf5610b11c; l_n_c=1; l_cap_id="ZTc0MjgxYjYxMWNkNDUxMGFmMGQ5Y2ZlYmE2NDgxYmI=|1529994964|cae58c665907a32ef8d27ad74a51eca98fe4f97a"; r_cap_id="MTJjYmJmYjIzYTBhNGQ4MWIyZmQzZDZmNWJhNGY5Mjc=|1529994964|3d6f86e368a9f9ac5cb945f334656c07d408c613"; cap_id="ZWRiNzhhNjg3YjFhNDhiMWEyMGE4NGIyYWQ0M2E4YTQ=|1529994964|a48525f631fa3ace981207f6a748b9936f38ce73"; n_c=1; __utma=51854390.1837640810.1529994966.1529994966.1529994966.1; __utmc=51854390; __utmz=51854390.1529994966.1.1.utmcsr=zhihu.com|utmccn=(referral)|utmcmd=referral|utmcct=/; __utmv=51854390.000--|3=entry_date=20180427=1; tgw_l7_route=860ecf76daf7b83f5a2f2dc22dccf049; capsion_ticket="2|1:0|10:1529998680|14:capsion_ticket|44:MzI5NDI3NmY0ZDg2NDhlOGIwNTRhYzM1ODhlNTJiYTY=|177bd3ed5d98ccee8ca6b291d12240aaedaf6f1325fcb08457c912e4fbfeef46"; z_c0="2|1:0|10:1529998692|4:z_c0|92:Mi4xLVV3eUFBQUFBQUFBZ0tQVXl5MmdEU1lBQUFCZ0FsVk5aRHNmWEFCcmdPU2JNODdhYWgyM00tZ1oxT3l5dnRiMmp3|ccb1e3c59663aec502eddd76f154e65479fef3005490def7b35d8e2956a07b8a"',
'host':'www.zhihu.com',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36'}
r=requests.get('https://www.zhihu.com',headers=headers)