Selenium get source

Selenium is a web automation module that can be used to get a webpages html code. In this article we will show how to achieve that.

You may need to set the path to chromium:

export PATH=$PATH:/usr/lib/chromium/

Related course
Selenium WebDriver and Python: WebTest Automation Course

Get html source
We import webdriver from the selenium module. A webdriver object is created (chromium) and we can optionally specify if we want to ignore certificate errors. Once the web browser started we navigate it to a webpage URL using the get() module. Then we get the page source.

from selenium import webdriver
import time
options = webdriver.ChromeOptions()
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(chrome_options=options)
html = driver.page_source

It will output the webpage source, which is stored in the variable html.

selenium chromium
Selenium will start the chromium browser automatically