gpt4 book ai didi

python - 如何使用pickle加载文件夹中的每个cookie文件

转载 作者:行者123 更新时间:2023-11-30 22:00:51 24 4
gpt4 key购买 nike

在我的cookies文件夹中,有很多文件cookies1.txt,cookies2.txt,...下面是我的脚本,我尝试用它来使用cookies登录facebook,每个cookie文件都会加载并执行一个操作然后完成并执行下一个加载文件,当我逐个运行每个cookie时它工作正常,但是当我将它们全部放入一个文件夹中时,它出现错误,有人可以帮助我吗?谢谢。

import os
import pickle
import selenium.webdriver


driver = selenium.webdriver.Firefox()
files = os.listdir("cookies")
for f in files:
cookies = pickle.load(open(f, "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
driver.get("http://www.facebook.com")

它显示:

Traceback (most recent call last):
File "C:/Users/tuong cat/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/new.py", line 10, in <module>
driver.add_cookie(cookie)


File "C:\Users\tuong cat\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 894, in add_cookie
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
File "C:\Users\tuong cat\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)


File "C:\Users\tuong cat\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidCookieDomainException: Message: Document is cookie-averse

最佳答案

我认为你必须在打开 URL 后添加 cookie

driver.get("http://www.facebook.com")
for f in files:
cookies = pickle.load(open(f, "rb"))
for cookie in cookies:
driver.add_cookie(cookie)

关于python - 如何使用pickle加载文件夹中的每个cookie文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54216079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com