1

I'm trying to get all results from a predefined google search, but I'm stuck at the following error:

Traceback (most recent call last):
  File "C:\python36\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
  File "C:\python36\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
 File "C:\python36\lib\subprocess.py", line 992, 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 "C:\Users\amzar\Desktop\pyscripts\selen.py", line 23, in <module>
get_results("dog")
File "C:\Users\amzar\Desktop\pyscripts\selen.py", line 6, in get_results
browser = webdriver.Firefox()
File "C:\python36\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
self.service.start()
File "C:\python36\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: 'geckodriver' executable needs to be in PATH.

I checked for 30 minutes all possibilities with importing, but I can't figured it out.

from selenium import webdriver

def get_results(search_term):
url = "http://startpage.com"
browser = webdriver.Firefox()
browser.get(url)
search_box = browser.find_element_by_id("query")
search_box.send_keys(search_term)
search_box.submit()
try:
    links = browser.find_elements_by_xpath("/ol[@class='web_regular_results']//h3//a")
except:
    links = browser.find_elements_by_xpath("//h3//a")
results = []
for link in links:
    href = link.get_attribute("href")
    printf(href)
    results.append(href)
browser.close()
return results

get_results("dog")

0 Answers0