老师,请问我的cookie——dict是正常的,但是rsp打印状态码一直是400,还有redis.cli也读不到cookie怎么处理

来源:11-10 实现检测网站cookie是否有效

qq_慕九州7150911

2020-03-27

E:\pycharm\CookieService\venv\Scripts\python.exe E:/pycharm/CookieService/services/zhihu.py
[{‘domain’: ‘www.zhihu.com’, ‘httpOnly’: False, ‘name’: ‘KLBRSID’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘9d75f80756f65c61b0a50d80b4ca9b13|1585301722|1585301719’}, {‘domain’: ‘zhihu.com’, ‘httpOnly’: False, ‘name’: ‘Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘1585301721’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1585301780, ‘httpOnly’: False, ‘name’: ‘_gat_gtag_UA_149949619_1’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘1’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1587823157.970984, ‘httpOnly’: False, ‘name’: ‘cap_id’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘“YWNmZDExNzQ3MWIyNDQwM2JkYWZjMWM3MDU0ZTJjZDc=|1585231157|dc54736598fdbad9434cecd4802b444f4b342a3e”’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1616837721, ‘httpOnly’: False, ‘name’: ‘Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘1585297580,1585298366,1585301630,1585301721’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1679813315.685079, ‘httpOnly’: False, ‘name’: ‘d_c0’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘“AFDe8wx6BRGPTsAUpPO1IWz-Z40BBgZkUME=|1585205315”’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1587823157.970944, ‘httpOnly’: False, ‘name’: ‘r_cap_id’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘“NWQ4YmJhODZlMDdhNGJkZTliZjdmODY3OTY1M2ExMWM=|1585231157|62da90f77ba152e968ad2d587cfefec68c4c6fa3”’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1587823157.970901, ‘httpOnly’: False, ‘name’: ‘l_cap_id’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘“MTYyODUzNDQwMzBkNDFhZTk2NDJmZDMxMmQ3NGU4YTQ=|1585231157|d34995cf41cbead325619b7c7ddf5e29fa252ce8”’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1600848002.712984, ‘httpOnly’: True, ‘name’: ‘z_c0’, ‘path’: ‘/’, ‘secure’: True, ‘value’: ‘“2|1:0|10:1585296003|4:z_c0|92:Mi4xM2Y4TERnQUFBQUFBVU43ekRIb0ZFU1lBQUFCZ0FsVk5nd0JyWHdCZVBBOUU4QjlsZUtXei1Ed1luWjA4MnJNbG5R|2fc94bf34f2dbcf8d0766e0b594ac64fda8f2a01d8e07d79dba6098e8ac29a20”’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1587888001.755287, ‘httpOnly’: True, ‘name’: ‘capsion_ticket’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘“2|1:0|10:1585296002|14:capsion_ticket|44:MTlmNDNjYWQxNTE1NGJjNWI0ODMzMGMwNjhiNjFiNjU=|948e07e103b460a7834d8785fb7ea152b345872004d8421ac30551c0fb2c3b7b”’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1585388120, ‘httpOnly’: False, ‘name’: ‘_gid’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘GA1.2.168505126.1585205314’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1648373720, ‘httpOnly’: False, ‘name’: ‘_ga’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘GA1.2.217146771.1585205314’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1587893721, ‘httpOnly’: False, ‘name’: ‘tst’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘r’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1648277312.996661, ‘httpOnly’: False, ‘name’: ‘_zap’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘1acf0328-047d-40f7-a95c-a58c9a8cb3d2’}, {‘domain’: ‘zhihu.com’, ‘expiry’: 1662965724.739905, ‘httpOnly’: False, ‘name’: ‘_xsrf’, ‘path’: ‘/’, ‘secure’: False, ‘value’: ‘FSeWRKE6EvkTlOAX2JQu35i7SY6cGQml’}]
{‘KLBRSID’: ‘9d75f80756f65c61b0a50d80b4ca9b13|1585301722|1585301719’, ‘Hm_lpvt_98beee57fd2ef70ccdd5ca52b9740c49’: ‘1585301721’, ‘_gat_gtag_UA_149949619_1’: ‘1’, ‘cap_id’: ‘“YWNmZDExNzQ3MWIyNDQwM2JkYWZjMWM3MDU0ZTJjZDc=|1585231157|dc54736598fdbad9434cecd4802b444f4b342a3e”’, ‘Hm_lvt_98beee57fd2ef70ccdd5ca52b9740c49’: ‘1585297580,1585298366,1585301630,1585301721’, ‘d_c0’: ‘“AFDe8wx6BRGPTsAUpPO1IWz-Z40BBgZkUME=|1585205315”’, ‘r_cap_id’: ‘“NWQ4YmJhODZlMDdhNGJkZTliZjdmODY3OTY1M2ExMWM=|1585231157|62da90f77ba152e968ad2d587cfefec68c4c6fa3”’, ‘l_cap_id’: ‘“MTYyODUzNDQwMzBkNDFhZTk2NDJmZDMxMmQ3NGU4YTQ=|1585231157|d34995cf41cbead325619b7c7ddf5e29fa252ce8”’, ‘z_c0’: ‘“2|1:0|10:1585296003|4:z_c0|92:Mi4xM2Y4TERnQUFBQUFBVU43ekRIb0ZFU1lBQUFCZ0FsVk5nd0JyWHdCZVBBOUU4QjlsZUtXei1Ed1luWjA4MnJNbG5R|2fc94bf34f2dbcf8d0766e0b594ac64fda8f2a01d8e07d79dba6098e8ac29a20”’, ‘capsion_ticket’: ‘“2|1:0|10:1585296002|14:capsion_ticket|44:MTlmNDNjYWQxNTE1NGJjNWI0ODMzMGMwNjhiNjFiNjU=|948e07e103b460a7834d8785fb7ea152b345872004d8421ac30551c0fb2c3b7b”’, ‘_gid’: ‘GA1.2.168505126.1585205314’, ‘_ga’: ‘GA1.2.217146771.1585205314’, ‘tst’: ‘r’, ‘_zap’: ‘1acf0328-047d-40f7-a95c-a58c9a8cb3d2’, ‘_xsrf’: ‘FSeWRKE6EvkTlOAX2JQu35i7SY6cGQml’}
400

Process finished with exit code 0

E:\redis\redis-windows-master\downloads\redis-64.3.0.503>redis-cli.exe
127.0.0.1:6379> keys *

  1. "zhihu_cookie"
    127.0.0.1:6379> smembers “zhihu_cookies”
    (empty list or set)
    127.0.0.1:6379> flushdb
    OK
    127.0.0.1:6379> smembers “zhihu_cookies”
    (empty list or set)
    127.0.0.1:6379> flushdb
    OK
    127.0.0.1:6379> smembers “zhihu_cookies”
    (empty list or set)
    127.0.0.1:6379> smembers “zhihu_cookies”
    (empty list or set)
    127.0.0.1:6379>
写回答

1回答

bobby

2020-03-28

你这里看起来并没有入库到redis中啊。你你有没有调试过代码 看看cookie是否入库到redis中了?

1
2
bobby
回复
qq_慕九州7150911
400你单独使用requests去去获取cookie然后请求一下看看是否没问题 如果是400那么看看具体返回的报错信息是什么
2020-03-30
共2条回复

Scrapy打造搜索引擎 畅销4年的Python分布式爬虫课

带你彻底掌握Scrapy,用Django+Elasticsearch搭建搜索引擎

5795 学习 · 6290 问题

查看课程