Welcome to News Scraper, an application I built to explore web scraping and understand its potential for automating data extraction. This tool fetches the top 5 news articles from popular sources like CNN, BBC, Telemundo, and Euronews, and displays them in a user-friendly interface using Python’s Tkinter library.
- Interactive Interface: A simple graphical interface powered by Tkinter.
- One-Click Scraping: Fetches and displays news headlines and clickable links with a single click.
- Real-Time Updates: Clears old results and fetches fresh news on every scrape.
- Cross-Platform Compatibility: Runs seamlessly on any system with Python installed.
Before running the application, ensure the following Python libraries are installed:
import tkinter as tk
from tkinter import scrolledtext
import requests
from bs4 import BeautifulSoup
from googletrans import Translator
import threading
import time
import webbrowser
Use pip install <library_name>
to install any missing dependencies.
The app targets specific news websites using a dictionary of URLs:
The scraper iterates through the dictionary to extract news headlines and links:
- Clear Previous Results: Clears the display area for new data.
- Fetch Content: Uses
BeautifulSoup
to parse the HTML of each site. - Extract Data: Finds specific HTML tags to fetch titles and links for each article.
- Display Data: Outputs the news title and a clickable link in the result box.
Here’s an example:
- Button: Created with
tk.Button
to define its size, font, and label.
- Scrollable Results Area: Built using
scrolledtext.ScrolledText
, allowing styled text display.
- Styled Text: Configured with
result_box.tag_config
for bold headlines, title fonts, and clickable links.
- Clock Widget: Displays the current time using
tk.Label
and updates every second viatime.strftime
. The clock runs on a separate thread to ensure smooth performance.
- Clone the repository.
- Install the required libraries.
- Run the script using
python app.py
. - Interact with the GUI to fetch and view news articles.
I’m open to suggestions! Feel free to fork this repository, improve the code, and submit a pull request. Let’s make this tool even better together.