From b9c496567fef576832c728abbe0de922fc516769 Mon Sep 17 00:00:00 2001 From: ZouJiu <1069679911@qq.com> Date: Wed, 22 Nov 2023 20:55:47 +0800 Subject: [PATCH] cookie not available, need login again --- README.md | 1 + crawler.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a9f233d..aac6e2b 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ python.exe crawler.py --think --article --answer --MarkDown ### 注意 1、需要较好的网速,本机网速测验是下载100Mbps,上传60Mbps,低点也可以的,不是太慢太卡就行[https://www.speedtest.cn/](https://www.speedtest.cn/)
2、爬取时设置了睡眠时间, 避免给知乎服务器带来太大压力,可以日间调试好,然后深夜运行爬取人少, 给其他小伙伴更好的用户体验, 避免知乎顺着网线过来找人,默认**6**s
+3、若是一直停在登录页面,可能是之前保存的cookie失效了,需要再次登录保存cookie ### blogs [https://www.aliyundrive.com/s/NikyVRJq8JV 阿里云分享的](https://www.aliyundrive.com/s/NikyVRJq8JV) `提取 0h3l`
diff --git a/crawler.py b/crawler.py index eb942de..5c8f8b6 100644 --- a/crawler.py +++ b/crawler.py @@ -925,7 +925,12 @@ def login_loadsavecookie(): try: load_cookie(driver, cookie_path) driver.get(r"https://www.zhihu.com/") - except: + except Exception as e: + if os.path.exists(cookie_path): + os.remove(cookie_path) + print("浏览器cookie失效了,删除了之前的cookie,需要再次登录并保存cookie。") + else: + print("需要登陆并保存cookie,下次就不用登录了。") driver = login(driver) save_cookie(driver, cookie_path) driver.quit()