The selenium module is used to control web browsers. You can control Chrome, Firefox, Chrome Mobile and many other browsers directly from Python code. You should know the basics of Python.
Install the selenium module and web driver. Use the python package manager pip to install the module.
pip3 install selenium
Each browser has a specific web driver. You can find a list of drivers on the selenium website.
For Chrome you need chromedriver. For Firefox you need geckodriver. The version of the driver needs to match the browser version on your pc.
After the driver and module are installed, you can fire up a browser. First thing to do is import the selenium module and the time module.
Then start a browser instance
Get the webpage:
So you have this code
#!/usr/bin/python3 from selenium import webdriver import time # start web browser browser=webdriver.Firefox() # get source code browser.get("https://twitter.com") html = browser.page_source time.sleep(2) print(html) # close web browser browser.close()
This then opens the browser and shows the HTML. You can interact with the browser just as you would normally do: click elements, type, scroll and much more.