Skip to content

Instantly share code, notes, and snippets.

@Hehehe421
Created October 10, 2023 00:15
Show Gist options
  • Save Hehehe421/0d5af3e00c26ba178179baeda925b378 to your computer and use it in GitHub Desktop.
Save Hehehe421/0d5af3e00c26ba178179baeda925b378 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
# Define the URLs of the news websites
urls = {
'BBC': 'https://www.bbc.com/news',
'NBC': 'https://www.nbcnews.com/',
'FOX': 'https://www.foxnews.com/',
}
# Initialize dictionaries to store trending news for each source
trending_news = {}
# Loop through the URLs and scrape trending news for each source
for source, url in urls.items():
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# Find and extract the trending news headlines (adjust based on website structure)
headlines = [headline.get_text().strip() for headline in soup.find_all('h3')]
trending_news[source] = headlines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment