Estou tentando aprender web scraping python, mas não consigo fazer o selenium funcionar com nenhum dos navegadores.
from selenium import webdriver
browser = webdriver.Firefox()
Este é todo o código que tenho e recebo isso por um erro.
Traceback (most recent call last):
File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "H:\codingpractice\python\python challenge.com.py", line 2, in <module>
browser = webdriver.Firefox()
File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
self.service.start()
File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00A11350>>
Traceback (most recent call last):
File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Users\tjhall\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Eu tentei tudo que posso encontrar na internet, desde adicionar o caminho ao código
from selenium import webdriver
browser = webdriver.Firefox("C:\Program Files (x86)\Mozilla Firefox\firefox.exe")
para adicioná-lo ao PATH em minhas variáveis de ambiente. Eu não consigo entender isso ...
Para Firefox e Chrome, agora você precisa baixar geckodriver / chromedriver . Esses drivers são necessários para a comunicação entre o navegador instalado e o selênio. Então você precisa:
pip install selenium
)Agora você pode adicionar o geckodriver ao seu caminho, conforme mencionado neste anwser . Ou você pode configurá-lo diretamente em seu código como este:
Chome: driver = webdriver.Chrome(executable_path='/path/to/chromedriver.exe')
Raposa de fogo: driver = webdriver.Firefox(executable_path='/opt/geckoDriver/geckodriver.exe')
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras