File tree Expand file tree Collapse file tree 1 file changed +18
-17
lines changed Expand file tree Collapse file tree 1 file changed +18
-17
lines changed Original file line number Diff line number Diff line change 11import bs4
2+ import lxml #xml parser
23from bs4 import BeautifulSoup as soup
34from urllib .request import urlopen
45
5- def news ():
6- #my_url="https://news.google.com/news/rss"
7- my_url = "https://news.google.com/news/rss?ned=in&hl=en-IN"
8- #To open the Given URL
9- Client = urlopen (my_url )
10- s_url = "https://news.google.com/news/headlines/section/topic/SPORTS.en_in/Sports?ned=in&hl=en-IN&gl=IN"
11- Client = urlopen (s_url )
12-
13-
14-
6+ def news (xml_news_url ):
7+
8+ Client = urlopen (xml_news_url )
159 xml_page = Client .read ()
1610 Client .close ()
17-
11+
1812 soup_page = soup (xml_page ,"xml" )
13+
1914 news_list = soup_page .findAll ("item" )
2015
2116 for news in news_list :
22- print (news .title .text )
23- print (news .link .text )
24- print (news .pubDate .text )
25- print ("-" * 150 )
26- n = input ()
17+ print ("\n " )
18+ print (news .title .text )
19+ print (news .link .text )
20+ print (news .pubDate .text )
21+ print ("\n " )
22+
2723
2824
25+ #you can add google news 'xml' URL here for any country/category
26+ news_url = "https://news.google.com/news/rss/?ned=us&gl=US&hl=en"
27+ sports_url = "https://news.google.com/news/rss/headlines/section/topic/SPORTS.en_in/Sports?ned=in&hl=en-IN&gl=IN"
2928
30- news ()
29+ #now call news function with any of these url or BOTH
3130
31+ news (news_url )
32+ news (sports_url )
You can’t perform that action at this time.
0 commit comments