I’m trying to implement a script in Python to scrape a website with Selenium.
In my script I need to delete a cookie and I’m following the documentation examples but I keep having errors.
I try to get the cookie as stated here, but I’m having this error:
➜ python scrape.py
Traceback (most recent call last):
File "/Users/user/scrape.py", line 19, in <module>
print(webdriver.get_cookie("akm"))
AttributeError: module 'selenium.webdriver' has no attribute 'get_cookie'
Here’s part of my script:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
PROXY = "http://127.0.0.1:8080"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument('--proxy-server=%s' % PROXY)
with webdriver.Chrome(options=chrome_options) as driver:
driver.get('https://www.website.net/')
print(webdriver.get_cookie("akm"))
And here’s the versions I’m using:
➜ python
Python 3.9.9 (v3.9.9, Nov 15 2021, 13:06:05)
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
>>> selenium.__version__
'4.21.0'
>>>
➜ chromedriver --version
ChromeDriver 125.0.6422.76