Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python谷歌新闻脚本_Python_Arrays_String_List - Fatal编程技术网

Python谷歌新闻脚本

Python谷歌新闻脚本,python,arrays,string,list,Python,Arrays,String,List,我的代码使用Python上的GoogleNews模块,并且只适用于列表中的第一个术语。因此,它只搜索第一个单词,并不断搜索第一个单词。如何让它搜索列表中的每个词?我对编码一无所知。您似乎只在第1页搜索关键字。您可以使用索引值i=。。。并在每个页面中搜索。我不熟悉这个库,所以我必须进行快速搜索,我认为您没有在所有页面中找到您要查找的关键字,因此可能需要扩展您的页面目录。就Python而言,没有任何错误,语法似乎没有问题。请阅读-总结是,这不是解决志愿者问题的理想方法,可能会对获得答案产生反作用。请

我的代码使用Python上的GoogleNews模块,并且只适用于列表中的第一个术语。因此,它只搜索第一个单词,并不断搜索第一个单词。如何让它搜索列表中的每个词?我对编码一无所知。

您似乎只在第1页搜索关键字。您可以使用索引值i=。。。并在每个页面中搜索。我不熟悉这个库,所以我必须进行快速搜索,我认为您没有在所有页面中找到您要查找的关键字,因此可能需要扩展您的页面目录。就Python而言,没有任何错误,语法似乎没有问题。

请阅读-总结是,这不是解决志愿者问题的理想方法,可能会对获得答案产生反作用。请不要将此添加到您的问题中。
from GoogleNews import GoogleNews
import sys
f = open("googlenewsx.txt", "w")
keywordlist = ['Apple', 'Pear','Orange']
googlenews = GoogleNews()
for word in keywordlist:
    googlenews.search(word)
    googlenews.setTimeRange('15/05/2020','15/06/2020')
    googlenews.getpage(1)
    results = googlenews.result()
    listofres = []
    for ting in results:
        title = ting['title']
        date = ting['date']
        link = ting['link']
        listofres += [[title, date, link]]
        f.write("%s, %s, %s \n" %(title, date, link))
#print(listofres)
#f.close()