До этого прекрасного вечера сохранял куки таким способом:
with open("cookie/1.pkl", "wb") as cookiefile:
pickle.dump(browser.get_cookies(), cookiefile)
а затем таким подгружал:
with open("cookie/1.pkl, "rb") as cookiefile:
cookies = pickle.load(cookiefile)
for cookie in cookies:
browser.add_cookie(cookie)
Сегодня попробовал переползти на PhantonJS и столкнулся с проблемой сохранения и загрузки cookies.
Выдает ошибку
selenium.common.exceptions.InvalidCookieDomainException: Message: {"errorMessage":"Can only set Cookies for the current domain","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Content-Length":"169","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:54294","User-Agent":"selenium/3.141.0 (python mac)"},"httpVersion":"1.1","method":"POST","post":"{\"cookie\": {\"domain\": \"ex.ru\", \"httponly\": false, \"name\": \"viewport\", \"path\": \"/\", \"secure\": false, \"value\": \"768\"}, \"sessionId\": \"3e5100e0-c44e-11e9-b7ad-81c50dc259c4\"}","url":"/cookie","urlParsed":{"anchor":"","query":"","file":"cookie","directory":"/","path":"/cookie","relative":"/cookie","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/cookie","queryKey":{},"chunks":["cookie"]},"urlOriginal":"/session/3e5100e0-c44e-11e9-b7ad-81c50dc259c4/cookie"}}
Screenshot: available via screen
Кто может подскать, как правильно работать с cookies на PhantomJS?