googleappengine的性能与本地应用不同

2024-09-30 09:22:50 发布

您现在位置:Python中文网/ 问答频道 /正文

以下函数将从Google搜索结果中提取url。它在dev_appserver(localhost)中运行良好,但当我将其部署到googleappengine上时,它显示出一些错误。在

程序:

def googleSearch(keyword):
    from re import findall
    from urllib2 import build_opener
    from urllib import quote, unquote
    urlregex = r'<a[ ]href="/url\?q=(http://.+?)[&]'
    searchURL = 'https://www.google.com/search?q=' + quote(keyword, safe = '') # https will exclude Cached results
    #Google
    opener = build_opener()
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    pagesource = opener.open(searchURL).read()
    result = findall(urlregex, pagesource)
    print result
    resultlist = []
    for url in result:
        resultlist.append(unquote(url))
    resultlist = sorted(set(resultlist), key=resultlist.index)
    return resultlist

GAE错误:

^{pr2}$

有人知道这个问题的解决办法吗。在


Tags: fromimportbuildurl错误googleresultopener
2条回答

使用旧的开发工具_服务器.apppy而不是dev_应用服务器.py. 在

可能是因为谷歌的数据存储索引还没有更新。稍等一会儿,它应该可以工作了。谷歌对此进行了解释here

Note: The Datastore Indexes may take some time to generate before your application is available. You will receive a NeedIndexError when accessing your app if the indexes are still in the process of being generated. This is a transient error for the example, so try a little later if at first you receive this exception.

相关问题 更多 >

    热门问题