Created
October 10, 2023 00:15
-
-
Save Hehehe421/0d5af3e00c26ba178179baeda925b378 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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