This Python script scrapes news articles from the G1 website, extracts their content, and generates short summaries using OpenAI's GPT model. The script fetches the latest news headlines, retrieves the full article text, and then summarizes it in a concise format.
- Scrapes news headlines and links from G1
- Extracts article content from the given links
- Summarizes the extracted content using OpenAI's GPT model
- Handles API rate limits with automatic retries
Before running the script, ensure you have the required dependencies installed:
pip install requests beautifulsoup4 openai python-dotenv- Clone this repository:
git clone https://github.com/ErickGCA/NewsScrap.git cd NewsScrap - Create a
.envfile and add your OpenAI API key:OPENAI_API_KEY=your_api_key_here - Run the script:
python newscrap.py
The script will:
- Fetch the latest news headlines from G1
- Display the first 5 headlines along with their links
- Extract the content of each article
- Summarize the content using OpenAI's GPT model
- Print the summarized news on the console
1. Example News Title
🔗 https://g1.globo.com/example-news-link
📝 Resumo: This is a short summary of the news article...
This project is open-source and available under the MIT License.