Skip to content

Commit a6e4dd9

Browse files
Merge pull request #429 from codePrady/master
Update Google_News.py
2 parents c57b10e + a06a15b commit a6e4dd9

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Google_News.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import bs4
22
import lxml #xml parser
3+
import ssl
34
from bs4 import BeautifulSoup as soup
45
from urllib.request import urlopen
56

67
def news(xml_news_url):
7-
'''Print select details from a html response containing xml
8+
9+
'''Print select details from a html response containing xml
810
@param xml_news_url: url to parse
911
'''
10-
Client=urlopen(xml_news_url)
12+
13+
context = ssl._create_unverified_context()
14+
Client=urlopen(xml_news_url, context=context)
1115
xml_page=Client.read()
1216
Client.close()
1317

@@ -16,20 +20,15 @@ def news(xml_news_url):
1620
news_list=soup_page.findAll("item")
1721

1822
for news in news_list:
19-
2023
print(f'news title: {news.title.text}')
2124
print(f'news link: {news.link.text}')
2225
print(f'news pubDate: {news.pubDate.text}')
2326
print("+-"*20,"\n\n")
24-
25-
26-
2727

2828
#you can add google news 'xml' URL here for any country/category
2929
news_url="https://news.google.com/news/rss/?ned=us&gl=US&hl=en"
3030
sports_url="https://news.google.com/news/rss/headlines/section/topic/SPORTS.en_in/Sports?ned=in&hl=en-IN&gl=IN"
3131

3232
#now call news function with any of these url or BOTH
33-
3433
news(news_url)
3534
news(sports_url)

0 commit comments

Comments
 (0)