0

I'm working to pass by the cookies acceptance windows that pop up once a website is loaded. I'm trying to achieve this by using 2 solutions described here: How to save and load cookies using Python + Selenium WebDriver with my implementation below. But the privacy settings keep on popping up on consecutive visits. I'd appreciate any resolution involving webdriver that passes by cookies.

Ad 1) First, I download cookies after my manual acceptance:

driver = webdriver.Firefox()
driver.get('https://www.forbes.com/')
# click accept 
pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))

And then I load them hoping that the website will be launched with my privacy consent:

driver = webdriver.Firefox()
driver.get('https://www.forbes.com/')
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
    driver.add_cookie(cookie)
    print(cookie)
# no luck in avoiding privacy settings

Ad 2) I'm adding an argument to options as described in the post linked above:

from selenium.webdriver.firefox.options import Options
fx_options = Options()
fx_options.add_argument('--user-data-dir=C:\\path\\to\\dir_where_my_cookies_file_is_saved') 
driver = webdriver.Firefox(options=fx_options)
driver.get('https://www.forbes.com/')
# no luck in avoiding privacy settings
kubs
  • 11
  • 3
  • Is there a reason why you don't accept the cookies everytime you visit the website? – borisdonchev Jul 02 '20 at 09:47
  • 1
    1) it saves time writing code to deal with pop-ups for new domains 2) in case of html changes impacting the privacy settings windows the code execution is not affected 3) performance – kubs Jul 02 '20 at 12:46

0 Answers0