A Python script that scrapes news articles from Kompas for a date range and saves them to a CSV file.
For each article, it collects the title, publish time, full text, tags, author, and URL. It goes through every page of the Kompas index for each date.
pip install requests beautifulsoup4 lxml python webscrapping.py
By default it scrapes January 2024 and saves the results to kompas_articles_2024.csv. To change the dates, edit start_date and end_date in scrape_articles_for_year.
- Sending HTTP requests and parsing HTML with BeautifulSoup
- Handling pagination and missing elements on real web pages
- Saving scraped data into a structured CSV dataset
The script depends on the current HTML structure of the Kompas website, so some selectors may need updating if the site changes.