Unable to add a cookie using Selenium & Splinter

走远了吗. 提交于 2019-12-01 00:39:21

you should open the url first, and load the cookies, then you can open the next url with cookies.you can also open like that if you want open the same url:

driver = webdriver.Chrome(executable_path=r'X:\home\xxx\chromedriver.exe')

cookies = pickle.load(open("cookies.pkl", "rb"))
driver.get("https://www.douban.com/")
for cookie in cookies:
    driver.add_cookie(cookie)
driver.get("https://www.douban.com/")

hope this helps

The answer of Florent B. works for me as well, just want to put it into the right place.

browser.cookies.add needs to be called after some browser.visit(...)

see Florent's comment:

The method browser.cookies.add is bound to the current domain which is undefined in your example. You need to set the domain first with driver.get('http://...')

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!