DEV Community

Everton Tenorio
Everton Tenorio

Posted on • Edited on

Automating Data Extraction with Selenium & SQLite

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?

  1. 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.

  2. CSV Download and Parsing: Using the requests library, the script downloads each CSV file containing the statistical data. Then, the csv library is used to parse and extract relevant information. This is represented by the download_and_parse_csv() function.

  3. 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
Enter fullscreen mode Exit fullscreen mode

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!

Billboard image

The fastest way to detect downtimes

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitoring.

Get started now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay