Web scraping, or data scraping, is extracting information from websites using code. Instead of opening a hundred pages and copying prices, a program visits each one and stores the data in a spreadsheet or database.
How it works
The program makes an HTTP request, receives the page HTML and looks for the elements that matter, such as title, price or date. For that it uses CSS selectors or XPath.
On pages that load data via JavaScript, an automated browser is used, such as Playwright, which opens the real page before reading.
Simple example to download a page:
curl -s https://exemplo.com/produtos -o produtos.htmlThen, an HTML parsing library extracts the desired fields.
Whenever an official API exists, prefer to use it: it is more stable and more correct than scraping the page.
Practical example
A store wants to track competitor prices. A script visits the product pages every morning, saves the prices in a spreadsheet and alerts when any drops below theirs. The person stops spending an hour a day on that check.
What it is for
- Monitor prices and stock.
- Gather jobs, news or ads in one place.
- Build datasets for analysis and research.
- Feed AI agents with up to date information.
Legal and ethical considerations
Read the site's terms of use and the robots.txt file. Do not overload the server with many requests in a row. Personal data requires attention to LGPD. Content protected by copyright cannot be copied and republished freely.
When in doubt, ask permission from the site owner or look for an official data source. It is also good to identify your program with a clear name and respect pauses between requests.
Difference between scraping and crawling
Scraping extracts data from specific pages. Crawling discovers pages by following links. Often the two work together.