Estoy comenzando a automatizar el libro de cosas aburridas y estoy tratando de abrir un navegador web Chrome a través de Python. Ya he instalado selenium y
He intentado ejecutar este archivo:
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys browser = webdriver.Chrome() browser.get('https://automatetheboringstuff.com')Pero por eso me sale este error:
Traceback (most recent call last): File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start stdout=self.log_file, stderr=self.log_file) File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 707, in __init__ restore_signals, start_new_session) File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 990, in _execute_child startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specifiedDurante el manejo de la excepción anterior, ocurrió otra excepción:
Traceback (most recent call last): File "C:/Program Files (x86)/Python36-32/test.py", line 5, in <module> browser = webdriver.Chrome() File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__ self.service.start() File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/homeDebe especificar la ruta donde se encuentra su chromedriver .
Descargue chromedriver para su plataforma deseada desde aquí .
Coloque chromedriver en la ruta de su sistema, o donde está su código.
Si no usa una ruta del sistema, vincule su chromedriver.exe (para usuarios que no usan Windows, simplemente se llama chromedriver ):
browser = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe") (Establezca executable_path en la ubicación donde se encuentra su chromedriver).
Si ha colocado chromedriver en su ruta del sistema, puede atajar simplemente haciendo lo siguiente:
browser = webdriver.Chrome()
Si está ejecutando un sistema operativo basado en Unix, es posible que deba actualizar los permisos de chromedriver después de descargarlo para que sea ejecutable:
chmod +x chromedriver
Eso es todo. Si aún tiene problemas, puede encontrar más información en este otro artículo de StackOverflow: No se puede usar el controlador Chrome para Selenium
Aquí hay una solución más simple: instale el paquete python-chromedrive, impórtelo en su secuencia de comandos y listo.
Paso a paso :
1. pip instalar chromedriver-binary
2. importar el paquete
from selenium import webdriver import chromedriver_binary # Adds chromedriver binary to path driver = webdriver.Chrome() driver.get("http://www.python.org")Referencia: https://pypi.org/project/chromedriver-binary/