File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 22import requests
33from bs4 import BeautifulSoup
44from .utils import editionMap , topicMap , langMap
5-
5+ from . userexception import NotFound
66
77class gnewsclient :
88
@@ -105,9 +105,9 @@ def set_params(self):
105105
106106 # setting location
107107 if self .location != None :
108- self .params ['geo' ] = self .location
109- # topic overrides location parameter. So, overriding it.
110- self .params ['topic' ] = None
108+ self .params ['geo' ] = self .location
109+ # topic overrides location parameter. So, overriding it.
110+ self .params ['topic' ] = None
111111
112112 # params setting successful
113113 return True
@@ -140,4 +140,10 @@ def scrape_feed(self, soup):
140140 article ['img' ] = None
141141 pass
142142 articles .append (article )
143+ try :
144+ if len (articles )== 0 :
145+ raise NotFound
146+ except NotFound :
147+ print ("The articles for the given response are not found" )
148+ return
143149 return articles
Original file line number Diff line number Diff line change 1+ #User defined exceptions for Gnewsclient
2+ class NotFound (Exception ):
3+ """Raised when the list articles in the function scapefeed() is empty"""
4+ pass
You can’t perform that action at this time.
0 commit comments