Exception: Could not parse your date
See original GitHub issueI have this very simple code
gn = GoogleNews()
start = datetime.date(2018,3,1)
end = datetime.date(2019,3,1)
print(start)
gn.search(query=“car”, from_=start.strftime(‘%Y-%m-%d’), to_=end.strftime(‘%Y-%m-%d’))
but it’s giving me the error of `
AttributeError Traceback (most recent call last) /opt/anaconda3/lib/python3.8/site-packages/pygooglenews/init.py in __from_to_helper(self, validate) 89 try: —> 90 validate = parse_date(validate).strftime(‘%Y-%m-%d’) 91 return str(validate)
/opt/anaconda3/lib/python3.8/site-packages/dateparser/conf.py in wrapper(*args, **kwargs) 84 —> 85 return f(*args, **kwargs) 86 return wrapper
/opt/anaconda3/lib/python3.8/site-packages/dateparser/init.py in parse(date_string, date_formats, languages, locales, region, settings) 52 —> 53 data = parser.get_date_data(date_string, date_formats) 54
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date.py in get_date_data(self, date_string, date_formats) 416 for locale in self._get_applicable_locales(date_string): –> 417 parsed_date = _DateLocaleParser.parse( 418 locale, date_string, date_formats, settings=self._settings)
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date.py in parse(cls, locale, date_string, date_formats, settings) 193 instance = cls(locale, date_string, date_formats, settings) –> 194 return instance._parse() 195
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date.py in _parse(self) 197 for parser_name in self._settings.PARSERS: –> 198 date_obj = self._parsersparser_name 199 if self._is_valid_date_obj(date_obj):
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date.py in _try_parser(self) 221 self._settings.DATE_ORDER = self.locale.info.get(‘date_order’, _order) –> 222 date_obj, period = date_parser.parse( 223 self._get_translated_date(), settings=self._settings)
/opt/anaconda3/lib/python3.8/site-packages/dateparser/conf.py in wrapper(*args, **kwargs) 84 —> 85 return f(*args, **kwargs) 86 return wrapper
/opt/anaconda3/lib/python3.8/site-packages/dateparser/date_parser.py in parse(self, date_string, settings) 36 stz = get_localzone() —> 37 date_obj = stz.localize(date_obj) 38 else:
AttributeError: ‘backports.zoneinfo.ZoneInfo’ object has no attribute ‘localize’
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last) <ipython-input-26-e0e962df0d1a> in <module> 26 return stories 27 —> 28 df = pd.DataFrame(get_news(‘Banana’))
<ipython-input-26-e0e962df0d1a> in get_news(search) 13 14 for date in date_list[:-1]: —> 15 search = gn.search(search, from_=date.strftime(‘%Y-%m-%d’), to_=(date+delta).strftime(‘%Y-%m-%d’)) 16 newsitem = search[‘entries’] 17
/opt/anaconda3/lib/python3.8/site-packages/pygooglenews/init.py in search(self, query, helper, when, from_, to_, proxies, scraping_bee) 139 140 if from_ and not when: –> 141 from_ = self.from_to_helper(validate=from) 142 query += ’ after:’ + from 143
/opt/anaconda3/lib/python3.8/site-packages/pygooglenews/init.py in __from_to_helper(self, validate) 91 return str(validate) 92 except: —> 93 raise Exception(‘Could not parse your date’) 94 95
Exception: Could not parse your date `
I would appreciate any help
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top GitHub Comments
For those who get similar problem. parse_validate has a problem make sure to comment it out, it’s a quick but not optimal solve
@bottaluscio I copied the script and commented out parse_validate part 😃 hope it works for you too