欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

【模拟登录】Python&cookie&17k

时间:2023-08-19
访问该网址时(17k.com),新用户需要注册 登入后便可查看到历史记录 案例

# 登录 => 得到cookie# 带着 cookie 去请求到书架url -> 书架上的内容# 必得得把上面的两个操作连起来# 我们可以使用session进行请求 -> session你可以认为是一连串的请求。在这个过程中的cookie不会丢失import requests# 会话(session) 意思是两个人座在一起聊天场景# session = requests.session()# data ={## "loginName": "18720107385",# "password": "18720107385.."## }# # 1.登录# url = "https://passport.17k.com/ck/user/login"# resp = session.post(url,data=data)# # print(resp.text)# # print(resp.cookies)### # 2.拿书架上的数据# # 刚才的那个session中是有cookie的# resp = session.get("https://user.17k.com/ck/author/shelf?page=1&appKey=2406394919")# print(resp.json())resp = requests.get("https://user.17k.com/ck/author/shelf?page=1&appKey=2406394919",headers ={"cookie": "GUID=6ea4826a-2d88-4e4b-8dc0-d9786258f153; sajssdk_2015_cross_new_user=1; c_channel=0; c_csc=web; _openId=ow-yN5nrdaRHsTccBbgL9hGeLIuM; BAIDU_SSP_lcr=https://open.weixin.qq.com/connect/qrconnect?response_type=code&appid=wxf134aca660749780&scope=snsapi_login&redirect_uri=https%3A%2F%2Fpassport.17k.com%2Fck%2Flogin%2Fcallback%2Fwechat%2Fweb%3FfromUrl%3Dhttps%253A%252F%252Fwww.17k.com%252F%253Fcode%253D1; Hm_lvt_9793f42b498361373512340937deb2a0=1643693266,1643693357,1643694241,1643694263; accessToken=avatarUrl%3Dhttps%253A%252F%252Fcdn.static.17k.com%252Fuser%252Favatar%252F06%252F66%252F29%252F91892966.jpg-88x88%253Fv%253D1643692603000%26id%3D91892966%26nickname%3D%25E8%25BF%2587%25E7%2581%25AB%25E4%25BA%2586%25E5%2590%25A7%26e%3D1659246474%26s%3Df86ca7c36628fdd1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2291892966%22%2C%22%24device_id%22%3A%2217eb3b487aec9-0606bb95d2a431-3d644509-1327104-17eb3b487af33a%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%7D%2C%22first_id%22%3A%226ea4826a-2d88-4e4b-8dc0-d9786258f153%22%7D; Hm_lpvt_9793f42b498361373512340937deb2a0=1643723571"})print(resp.text)

运行结果

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。