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

在我的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


慕桂英3389331
浏览 200回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python