File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change 11import bs4
22import lxml #xml parser
3+ import ssl
34from bs4 import BeautifulSoup as soup
45from urllib .request import urlopen
56
67def 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
2929news_url = "https://news.google.com/news/rss/?ned=us&gl=US&hl=en"
3030sports_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-
3433news (news_url )
3534news (sports_url )
You can’t perform that action at this time.
0 commit comments