Python-cookie登录的基本使用

'''
1、登录 -> 拿到cookie
2、带着cookie去请求url -> 拿到里面内容
3、使用session进行一连串请求,不会导致cookie丢失
'''

import requests

session = requests.session()
data = {
    "loginName": 12345678911,
    "password": "12345678922"
}

url = "https://passport.17k.com/ck/user/login"
session.post(url, data=data)
# print(resp.cookies)

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=f9fff4a8-3101-4b8a-b29a-b1cb2beaacb3; sajssdk_2015_cross_new_user=1; Hm_lvt_9793f42b498361373512340937deb2a0=1655801330; c_channel=0; c_csc=web; BAIDU_SSP_lcr=https://graph.qq.com/oauth2.0/show?which=Login&display=pc&response_type=code&client_id=215314&scope=get_user_info&redirect_uri=https%3A%2F%2Fpassport.17k.com%2Fsns%2FqqCallback.action%3FfromUrl%3Dhttps%253A%252F%252Fwww.17k.com%252F; accessToken=avatarUrl%3Dhttps%253A%252F%252Fcdn.static.17k.com%252Fuser%252Favatar%252F07%252F67%252F44%252F97104467.jpg-88x88%253Fv%253D1655801509000%26id%3D97104467%26nickname%3Dpythonnnn%26e%3D1671353540%26s%3D59e44ffcfb6925c4; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2297104467%22%2C%22%24device_id%22%3A%2218185733a0a372-01989555b8fb9a-50684254-921600-18185733a0c6df%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E5%BC%95%E8%8D%90%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Fshow%3Fwhich%3DLogin%26display%3Dpc%26response_type%3Dcode%26client_id%3D215314%26scope%3Dget_user_info%26redirect_uri%3Dhttps%253A%252F%252Fpassport.17k.com%252Fsns%252FqqCallback.action%253FfromUrl%253Dhttp%22%2C%22%24latest_referrer_host%22%3A%22graph.qq.com%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%7D%2C%22first_id%22%3A%22f9fff4a8-3101-4b8a-b29a-b1cb2beaacb3%22%7D; Hm_lpvt_9793f42b498361373512340937deb2a0=1655801671"})
print(resp.json())

你可能感兴趣的:(Python爬虫,cookie,python,爬虫)