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 1
1
import bs4
2
2
import lxml #xml parser
3
+ import ssl
3
4
from bs4 import BeautifulSoup as soup
4
5
from urllib .request import urlopen
5
6
6
7
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
8
10
@param xml_news_url: url to parse
9
11
'''
10
- Client = urlopen (xml_news_url )
12
+
13
+ context = ssl ._create_unverified_context ()
14
+ Client = urlopen (xml_news_url , context = context )
11
15
xml_page = Client .read ()
12
16
Client .close ()
13
17
@@ -16,20 +20,15 @@ def news(xml_news_url):
16
20
news_list = soup_page .findAll ("item" )
17
21
18
22
for news in news_list :
19
-
20
23
print (f'news title: { news .title .text } ' )
21
24
print (f'news link: { news .link .text } ' )
22
25
print (f'news pubDate: { news .pubDate .text } ' )
23
26
print ("+-" * 20 ,"\n \n " )
24
-
25
-
26
-
27
27
28
28
#you can add google news 'xml' URL here for any country/category
29
29
news_url = "https://news.google.com/news/rss/?ned=us&gl=US&hl=en"
30
30
sports_url = "https://news.google.com/news/rss/headlines/section/topic/SPORTS.en_in/Sports?ned=in&hl=en-IN&gl=IN"
31
31
32
32
#now call news function with any of these url or BOTH
33
-
34
33
news (news_url )
35
34
news (sports_url )
You can’t perform that action at this time.
0 commit comments