|
5 | 5 | from urllib.request import urlopen |
6 | 6 |
|
7 | 7 | def news(xml_news_url): |
8 | | - |
9 | | - '''Print select details from a html response containing xml |
10 | | - @param xml_news_url: url to parse |
11 | | - ''' |
12 | | - |
13 | | - context = ssl._create_unverified_context() |
14 | | - Client=urlopen(xml_news_url, context=context) |
15 | | - xml_page=Client.read() |
16 | | - Client.close() |
17 | | - |
18 | | - soup_page=soup(xml_page,"xml") |
19 | | - |
20 | | - news_list=soup_page.findAll("item") |
21 | | - |
22 | | - for news in news_list: |
23 | | - print(f'news title: {news.title.text}') |
24 | | - print(f'news link: {news.link.text}') |
25 | | - print(f'news pubDate: {news.pubDate.text}') |
26 | | - print("+-"*20,"\n\n") |
27 | | - |
28 | | -#you can add google news 'xml' URL here for any country/category |
| 8 | + |
| 9 | + '''Print select details from a html response containing xml |
| 10 | + @param xml_news_url: url to parse |
| 11 | + ''' |
| 12 | + |
| 13 | + context = ssl._create_unverified_context() |
| 14 | + Client=urlopen(xml_news_url, context=context) |
| 15 | + xml_page=Client.read() |
| 16 | + Client.close() |
| 17 | + |
| 18 | + soup_page=soup(xml_page,"xml") |
| 19 | + |
| 20 | + news_list=soup_page.findAll("item") |
| 21 | + |
| 22 | + for news in news_list: |
| 23 | + print(f'news title: {news.title.text}') |
| 24 | + print(f'news link: {news.link.text}') |
| 25 | + print(f'news pubDate: {news.pubDate.text}') |
| 26 | + print("+-"*20,"\n\n") |
| 27 | + |
| 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 | | -news(news_url) |
| 33 | +news(news_url) |
34 | 34 | news(sports_url) |
0 commit comments