π° Scraping and Summarizing Kenyan Political News with Python

In this blog, Iβll walk you through how I built a Python script that scrapes political news from Standard Media Kenya, summarizes each article using NLP, and saves the results to a .txt
file.
π οΈ What I Built
I wanted a simple tool to help me stay up to date with Kenyan politics β without manually reading every article.
So I built a Python script that:
Scrapes article links from the Politics section
Downloads and parses the full article using
newspaper3k
Summarizes each article into 3 sentences using
Sumy
(LexRank)Saves the title, URL, summary, and full text to a
.txt
file
π§ Tools and Libraries Used
requests
+BeautifulSoup
β for scrapingnewspaper3k
β for extracting full article textsumy
β for summarizing using LexRanknltk
β for tokenizationtime
β for basic delays (not used for auto-scheduling now)
β οΈ What I Struggled With
π Problem: Many URLs were either incomplete or unusable
β
Fix: I checked and cleaned URLs early before passing to Article()
.
π Problem: Some articles didnβt load or were empty
β
Fix: Wrapped downloads in a try-except
block to skip broken links safely.
π Problem: Summaries were hard to read in the output
β
Fix: Clean formatting and line breaks made the .txt
readable.
π Output
The .txt
file contains:
β Title of each article
β Link to the article
β 3-sentence summary
Each article is neatly separated with clear headings and lines.
π¦ GitHub Repo
π View the full project on GitHub
π‘ Final Thoughts
This small but powerful project helped me improve my scraping and NLP skills. If youβre looking to automate news consumption or build a simple NLP tool, this is a great place to start.
Subscribe to my newsletter
Read articles from kasumbi phil directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
