Objective: Present a simple use case of data extraction with Selenium and storing in a SQLite database, where files are downloaded and can be analyzed for new insights.
Code
I created a Python script that accesses the StatCounter website and downloads all statistical data on platform usage in Brazil over the years.
The script is available here. Make sure you have the necessary libraries installed - read the README.md - and Selenium configured with Chrome Driver.
How does it work?
Chrome Headless Configuration: Selenium is configured with Chrome's headless option to automate website navigation without a graphical interface. This is handled by the
configure_chrome_headless()
function.CSV Download and Parsing: Using the
requests
library, the script downloads each CSV file containing the statistical data. Then, thecsv
library is used to parse and extract relevant information. This is represented by thedownload_and_parse_csv()
function.Storage in SQLite: Tables are created and updated in an SQLite database, organizing the data by year. This is handled by the
save_to_sqlite()
function.
python platform_market_share.py
I hope to bring more use cases exemplifying the use of Selenium with Python code, as there are many other interesting things to do with these technologies. Share by commenting below any example of a case you know or have developed!
Top comments (0)