GoogleNews- pygooglenews -Could not parse your date error

806 views Asked by At

Using pygooglenews a month ago and it was working, however now there seems to be an error: Could not parse your date

Does anyone know how to bypass this or six this issue?

gn = GoogleNews(lang = 'en')

def get_news(search):
   stories = []
   start_date = datetime.date(2020,1,1)
   end_date = datetime.date(2021,12,31)
   delta = datetime.timedelta(days=1)
   date_list = pd.date_range(start_date, end_date).tolist()

for date in date_list[:-1]:
    result = gn.search(search, from_=(date).strftime('%Y-%m-%d'), to_=(date+delta).strftime('%Y-%m-%d'))
    newsitem = result['entries']

    for item in newsitem:
        story = {
            'title':item.title,

            'link':item.link,
            'published':item.published
        }
        stories.append(story)

return stories

I also tried just changing to simple date format

gn.search('Christmas', helper = True, from_ = '2019/12/01', to_= '2019/12/31')

and still getting Could not parse your date error.

2

There are 2 answers

0
Chi-Yuan Li On

I also had the same problem but I fixed it by reinstall the regex package. Here is what I did.

!pip install regex==2022.3.2

And my problem fixed.

I search the several source to find the problem, it seems that the lastest regex is buggy. Therefore, when you downgrade your regex version, it might help.

Hope this solution help you!

3
user19419589 On

THe main reason is because the format is mm/dd/yy so you need to change to

gn.set_time_range('12/01/2019','12/31/2019')
gn.set_encode('utf-8')
gn.search('Christmas')