Created
June 7, 2019 02:39
-
-
Save rosswd/2c7f9b95083a553ba8790e2f28fc5838 to your computer and use it in GitHub Desktop.
Headless search using Selenium in Python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| selenium==3.141.0 | |
| urllib3==1.25.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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