Skip to content

Commit acba98f

Browse files
committed
Update Google_News.py
- Added code to opt out of certificate verification to fix the below error - ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
1 parent 711af36 commit acba98f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Google_News.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
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):
78

8-
Client=urlopen(xml_news_url)
9+
context = ssl._create_unverified_context()
10+
Client=urlopen(xml_news_url, context=context)
911
xml_page=Client.read()
1012
Client.close()
1113

@@ -14,20 +16,16 @@ def news(xml_news_url):
1416
news_list=soup_page.findAll("item")
1517

1618
for news in news_list:
17-
1819
print(news.title.text)
1920
print(news.link.text)
2021
print(news.pubDate.text)
2122
print("\n\n")
22-
23-
2423

2524

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

3029
#now call news function with any of these url or BOTH
31-
3230
news(news_url)
3331
news(sports_url)

0 commit comments

Comments
 (0)