Google search to retrieve number of results for search keywords

为君一笑 提交于 2019-12-19 22:27:51

问题


I am having a list of keywords and would like to know the number of results for google search for each of those(for my research project). I am using the below code for the same.

def showsome(searchfor):
    hits = -1
    try:
            query = urllib.urlencode({'q': searchfor})
            url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query
            search_response = urllib.urlopen(url)
            search_results = search_response.read()
            results = json.loads(search_results)
            data = results['responseData']
            print 'Total results for %s: %s' % (searchfor,data['cursor']['estimatedResultCount'])
            hits = int(data['cursor']['estimatedResultCount'])
    except:
            #error.write(formatExceptionInfo())
            traceback.print_exc(file=error)
            error.write("\n")

    return hits

But after some 1000 results, I am not getting any results. Is there an alternative way to query google? I checked google custom search API and it allows only 100 results per day.

来源:https://stackoverflow.com/questions/4785833/google-search-to-retrieve-number-of-results-for-search-keywords

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!