I’m working this code:
from selenium import webdriver
from `selenium.webdriver.firefox.choices` import Choices
Setup:
choices = Choices()
choices.add_argument("--headless")
def get_results(search_term):
url = "https://www.wikipaedia.org"
browser = webdriver.Firefox(firefox_options=choices, executable_path=r"/usr/native/bin/geckodriver")
browser.get(url)
search_box = browser.find_element_by_id("question")
search_box.send_keys(search_term)
search_box.submit()
attempt:
hyperlinks = browser.find_elements_by_xpath("//ol[@class="web_regular_results"]//h3//a")
besides:
hyperlinks = browser.find_elements_by_xpath("//h3//a")
outcomes = []
for hyperlink in hyperlinks:
href = hyperlink.get_attribute("href")
print(href)
outcomes.append(href)
browser.shut()
return outcomes
I am getting error messages:
Traceback (most up-to-date name final):
File "search_items.py", line 37, in
get_results("canine")
File "search_items.py", line 13, in get_results
search_box = browser.find_element_by_id("question")
File "/usr/native/lib/python2.7/dist-packages/selenium/webdriver/distant/webdriver.py", line 351, in find_element_by_id
return self.find_element(by=By.ID, worth=id_)
File "/usr/native/lib/python2.7/dist-packages/selenium/webdriver/distant/webdriver.py", line 955, in find_element
'worth': worth})['value']
File "/usr/native/lib/python2.7/dist-packages/selenium/webdriver/distant/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/native/lib/python2.7/dist-packages/selenium/webdriver/distant/errorhandler.py", line 242, in check_response
elevate exception_class(message, display screen, stacktrace)
selenium.widespread.exceptions.NoSuchElementException: Message: Unable to find ingredient: [id="query"]
I’ve tried to unravel however it’s past me.
Any assist could be significantly appreciated.