-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleNews.py
More file actions
24 lines (20 loc) · 761 Bytes
/
GoogleNews.py
File metadata and controls
24 lines (20 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import feedparser
# # Using RSS feeder
# url = 'https://news.google.com/news/rss' # Replace with any specific feed URL
# feed = feedparser.parse(url)
#
# for entry in feed.entries[:5]: # Top 5 headlines
# print(entry.title)
# Using Web Scraping
import requests
from bs4 import BeautifulSoup
url = 'https://news.google.com'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
headlines = soup.find_all('h3')
print(f"Headlines Count: {len(headlines)}")
for headline in headlines:
if headline.find(attrs={'href': True}):
print("{}: {}".format(headline.get_text(), (headline.find(attrs={'href': True}).get('href')).replace(".", url)))
else:
print("{}: No href link attached".format(headline.get_text()))