Web scraping means using a program to download web pages and copy specific pieces of data out of them into a structured form: a spreadsheet, a JSON file or a database. Instead of opening fifty product pages and typing each price into a sheet, a scraper fetches the pages and collects the prices for you. It's also called web data extraction or web harvesting.
Scraping, crawling and APIs
These three often come up together, and they're different jobs.
- Crawling is finding and fetching pages, usually by following links from page to page. Search engines crawl the web to build their index. See crawler.
- Scraping is pulling particular fields out of pages: the price, the title, the date, the list of links. A project can crawl to find pages and then scrape each one.
- An API is a door a site opens on purpose, returning data in a clean format with clear rules on use. When a site offers an API or a feed for the data you need, it's usually more reliable and less disputed than scraping its pages.
What people use it for
- Price and stock monitoring across competitors' online shops
- Search and SEO research, such as recording which pages rank for a set of searches, or collecting page titles, headings and links during a site audit
- Market research: listings, job ads, reviews or public records gathered from many sites
- Monitoring changes on pages you care about, such as terms, prices or a competitor's product range
- Archiving and research by libraries, journalists and academics
- Training data for AI models, collected at very large scale
How a scraper works
Every scraper does three things:
- Fetch. It requests the page over HTTP, as a browser would. Pages that build their content with JavaScript may need a headless browser, a real browser engine without a screen, so the content exists before extraction.
- Extract. It finds the data in the page's HTML, usually with CSS selectors or XPath expressions that point to specific elements, such as "the text inside the element with class
price". - Store. It saves the fields in a structured format and often records when each page was fetched, so you can compare over time.
The weak point is step 2. When a site redesigns its pages, selectors stop matching and the scraper silently returns empty or wrong values. Check the output regularly.
Is web scraping legal?
There's no single answer. It depends on the country, what you collect, how you get it and what you do with it. These are the questions that decide most cases:
- What do the site's terms of service say? Many sites forbid automated collection. Read them before you start, especially if you have an account on the site: you accepted its terms when you signed up.
- Are you getting past a barrier? Collecting pages anyone can open is different from logging in, using someone else's account or working around blocks.
- Is the content protected by copyright? Collecting facts such as prices is different from copying and republishing articles, photos or reviews.
- Does the data identify people? In the EU, names, email addresses, IP addresses and other information about identifiable people are personal data under the GDPR (European Commission). Collecting and using it has to follow the law's principles, such as lawfulness and data minimization, and the people concerned keep rights over it.
This is general information, not legal advice. For anything commercial, or anything involving personal data, ask a lawyer who knows your country's rules.
How to scrape politely
A scraper puts load on someone else's server. These habits keep you from causing harm and from getting blocked:
- Read robots.txt and follow it. Robots.txt is a request, not a lock: the standard says its rules are not a form of access authorization. Following it shows you respect the site owner's wishes.
- Say who you are. Send a user agent that names your bot; the robots.txt standard expects the bot's name (its product token) to appear there. Add a link to a page that explains what the bot does and how to reach you. Don't disguise a bot as a normal browser to get around a site's rules.
- Go slowly. Space out requests and fetch from one site at a time. If the server answers with 429 Too Many Requests, wait. A
Retry-Afterheader tells you how long (MDN). Treat 5xx errors the same way: Google's own crawlers read HTTP 500 errors as a signal to slow down. - Don't fetch what you already have. Cache pages and re-fetch only when you need fresh data.
- Collect only what you need. Fewer fields and fewer pages mean less load and less legal exposure.
Scraped content and search rankings
Using scraped data for research is one thing; publishing scraped content is another. Google's spam policies name scraping as a violation when sites republish other sites' content or feeds, or lightly reword it, without adding value. Sites that break these policies may rank lower or not appear in Google's results at all. If you use scraped data on a public page, the value should come from what you add: analysis, comparison or your own information.