简体   繁体   English

GoogleNews- pygooglenews - 无法解析您的日期错误

[英]GoogleNews- pygooglenews -Could not parse your date error

Using pygooglenews a month ago and it was working, however now there seems to be an error: Could not parse your date一个月前使用 pygooglenews 并且可以正常工作,但是现在似乎出现错误: 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.并且仍然Could not parse your date错误。

THe main reason is because the format is mm/dd/yy so you need to change to主要原因是因为格式是mm/dd/yy所以需要改成

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

It seems that there is a bug in dataparser , which pygooglenews uses. pygooglenews使用的dataparser似乎存在一个错误。 To fix this issue you need to install regex==2022.3.2要解决此问题,您需要安装regex==2022.3.2

This will fix your 'could not parse your date error'这将解决您的“无法解析您的日期错误”

Here is a Google Colab that shows it working.这是一个谷歌 Colab ,它显示了它的工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 GoogleNews 抓取新闻时出错 - “没有名为 GoogleNews 的模块” - Error when news scraping with GoogleNews - "No module named GoogleNews" 错误无法解析python中的命令 - error could not parse command in python “无法解析提醒错误”-django - “Could not parse reminder error” - django 配置:错误:在您的系统上找不到 pthreads - configure: error: could not find pthreads on your system GoogleNews-vectors-negative300.bin导致word2vec错误 - Error for word2vec with GoogleNews-vectors-negative300.bin 错误:virtualenvwrapper 在您的路径中找不到 virtualenv - ERROR: virtualenvwrapper could not find virtualenv in your path 我得到“服务器遇到错误,无法完成您的请求”错误 - Im getting “The server encountered an error and could not complete your request” error 使用GoogleNews-vectors-negative300.bin构建字典返回ValueError:无法将字符串转换为float - Building dictionary with GoogleNews-vectors-negative300.bin returns ValueError: could not convert string to float 无法解析Django URL参数的余数错误 - Could not parse the remainder error on django url parameters 如何解决TemplateSyntaxError:无法解析余数错误? - How to resolve TemplateSyntaxError: Could not parse the remainder error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM