Free

News Web Scraper

Parse the structure, not the text — and be a client the site would not mind.

  • Python
  • BeautifulSoup
  • requests

About this project

A scraper that extracts headlines, links, sections and summaries from a news listing page and writes them to CSV. It ships with a sample page and runs entirely offline by default, so it works on any connection and without asking anything of a site you do not own.

The idea it is built around is that you parse the structure, not the text. A regular expression over HTML looks like it works and breaks the first time an attribute order changes or a tag gains a class — the README shows a specific input where the regex quietly returns the wrong thing and the parser keeps working.

The second theme is not optional and gets equal space: being a client the site would not mind. Identify yourself with a real User-Agent, leave a gap between requests, read robots.txt before fetching, and cache locally so re-running does not re-fetch. The project says plainly that scraping a site you do not own may breach its terms, and the bundled sample exists so that nobody has to in order to learn this.

What you will learn

  • Parse HTML by structure with BeautifulSoup rather than pattern-matching it with a regex
  • See a concrete case where the regex version breaks and the parser does not
  • Write to CSV correctly, including fields that themselves contain commas
  • Behave as a polite client: identify yourself, rate-limit, honour robots.txt and cache
  • Resolve relative links against a base URL

Before you start

  • Python basics — functions, lists and dictionaries
  • Python 3.10 or newer, plus requests and beautifulsoup4 (one pip command)
  • A little HTML — what a tag, a class and an attribute are

New to Python? The free Python course covers everything this project assumes.

Academic integrity notice

These projects are provided for learning, experimentation and reference. Understand the code, modify it for your own requirements, and acknowledge external work according to your institution’s academic policies. Priodemy does not supply work to be submitted as your own.