In my cookies folder, there are many files cookies1.txt, cookies2.txt, ... and below is my script, I try to use it to login facebook with cookies, with each cookie file it will load and execute an action then finish and perform the next load file, it works fine when I run each cookie one by one but when I put them all in a folder, it appears an error, can someone help me? Thank you.
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")
It shows:
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