用谷歌新闻抓取报纸文章标题

时间:2021-01-23 18:31:45

标签: python web-scraping google-news

以下是我用于抓取有关家庭暴力的新闻的代码。这段代码在我第一次使用时运行良好。但当时我只涵盖了 2-3 个月的时间,我在更宽的时间范围内重新尝试,它返回一个空字符串。为什么会这样,我该如何解决?

from GoogleNews import GoogleNews
from newspaper import Article
import pandas as pd

googlenews = GoogleNews(start='24/01/2020', end='23/01/2021')
googlenews.search('Domestic violence')
result = googlenews.result()
df = pd.DataFrame(result)
print(df.head())

for i in range(2,20):
    googlenews.getpage(i)
    result = googlenews.result()
    df = df.append(result)
    df = pd.DataFrame(df)

非常感谢!

1 个答案:

答案 0 :(得分:1)

我找到了答案。我把日期格式写错了。应该是 01/24/2020

相关问题