Forums

Can´t run selenium

I have this code to webscrape some websites and it gives me error i already pip installed everything

from pyvirtualdisplay import Display
    from selenium import webdriver
    PTTEAMS = ['https://www.meusresultados.com/equipa/fc-porto/S2NmScGp/resultados/',
    'https://www.meusresultados.com/equipa/benfica/zBkyuyRI/resultados/',
    'https://www.meusresultados.com/equipa/sporting/tljXuHBC/resultados/',
    'https://www.meusresultados.com/equipa/braga/dpUer7ht/resultados/',
    'https://www.meusresultados.com/equipa/rio-ave/jPzXLi4l/resultados/',
    'https://www.meusresultados.com/equipa/chaves/vsToxqA5/resultados/',
    'https://www.meusresultados.com/equipa/maritimo/noguvetP/resultados/',
    'https://www.meusresultados.com/equipa/boavista/n5XEAYKe/resultados/',
    'https://www.meusresultados.com/equipa/vitoria-guimaraes/pQYVZyD2/resultados/',
    'https://www.meusresultados.com/equipa/portimonense/6ecm9Xlr/resultados/',
    'https://www.meusresultados.com/equipa/tondela/nFFgCnVo/resultados/',
    'https://www.meusresultados.com/equipa/belenenses/fyrUnmpP/resultados/',
    'https://www.meusresultados.com/equipa/aves/voyKqfCR/resultados/',
    'https://www.meusresultados.com/equipa/setubal/pnrBoGsF/resultados/',
    'https://www.meusresultados.com/equipa/moreirense/8d9NGt9H/resultados/',
    'https://www.meusresultados.com/equipa/feirense/t4p0iC41/resultados/',
    'https://www.meusresultados.com/equipa/pacos-ferreira/hxT1f5xa/resultados/',
    'https://www.meusresultados.com/equipa/estoril/htoKuYZl/resultados/']


    jogos = []

    with Display():
        # we can now start Firefox and it will run inside the virtual display
        browser = webdriver.Firefox()
        # put the rest of our selenium code in a try/finally
        # to make sure we always clean up at the end
        try:
            for k in PTTEAMS:
                browser.get(k)
                for i in browser.find_elements_by_tag_name('tr'):
                    jogos.append("https://www.meusresultados.com/jogo/"+i.get_attribute('id')[4:12:1]+"/#estatisticas-de-jogo;0")
            gg = list(set(jogos))

        finally:
            browser.quit()

The error :

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/usr/lib/python3.6/subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1326, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/darthnox/hello.py", line 27, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 140, in __init__
    self.service.start()
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 81, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Take a look at our help pages for the correct version of selenium needed. But as a free user you most likely won't be able to do what you are trying to do because you can only access sites that are on our whitelist.