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 can use the web drivers attribute .page_source to grab the html code of any webpage.
If you are new to selenium, I recommend the course below.
Browser Automation with Python Selenium
If you haven’t done so, install the selenium module (pip), the web browser and the web driver.
For this example, you may need to set the path to chromium:
You can import thet webdriver from the selenium module. A webdriver object is created (chromium) and we can optionally specify if we want to ignore certificate errors.
Of course any web browser can be used, but for this example I’ve used chromium.
Once the web browser started we navigate it to a webpage URL using the get() module. Then we get the page source.
It will output the webpage source, which is stored in the variable html.