Skip to content

Instantly share code, notes, and snippets.

@rosswd
Created June 7, 2019 02:39
Show Gist options
  • Select an option

  • Save rosswd/2c7f9b95083a553ba8790e2f28fc5838 to your computer and use it in GitHub Desktop.

Select an option

Save rosswd/2c7f9b95083a553ba8790e2f28fc5838 to your computer and use it in GitHub Desktop.
Headless search using Selenium in Python3
selenium==3.141.0
urllib3==1.25.3
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
# Setup for headless running
opts = Options()
opts.headless = True
assert opts.headless
browser = webdriver.Firefox(options=opts)
browser.get("https://duckduckgo.com/")
assert "DuckDuckGo" in browser.title
search_form = browser.find_element_by_id("search_form_input_homepage")
search_form.send_keys("the expanse")
search_form.submit()
browser.implicitly_wait(3)
results = browser.find_elements_by_class_name("result")
print(results[1].text)
browser.close()
quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment