Unable to add a cookie using Selenium & Splinter

后端 未结 2 1816
青春惊慌失措
青春惊慌失措 2021-01-07 04:30

Per below, I\'m not sure how to troubleshoot this pretty simple usage scenario.

I have script (that I run about once a month) that functionally does the identical th

相关标签:
2条回答
  • 2021-01-07 04:42

    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://...')

    0 讨论(0)
  • 2021-01-07 04:54

    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

    0 讨论(0)
提交回复
热议问题