J'ai cherché sur stackoverflow et je n'ai pas trouvé de solution à ce problème. Les solutions que j'ai trouvées étaient apparemment anciennes.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})
driver = webdriver.Chrome(chrome_options=chrome_options)
Voici l'erreur que j'obtiens
Traceback (most recent call last):
File "C:\Users\amete\Documents\Python\Code\Web test.py", line 10, in <module>
driver = webdriver.Chrome(chrome_options=chrome_options)
File "C:\Users\amete\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\amete\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1
Mon code :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = r"C:\Users\amete\Documents\chromedriver.exe"
driver = webdriver.Chrome(PATH)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.google.com/")
print (driver.title)
search = driver.find_element_by_id("input")
search.send_keys("One Piece")
search.send_keys(Keys.RETURN)
time.sleep(5)
driver.quit()