以下函数将从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}$有人知道这个问题的解决办法吗。在
使用旧的开发工具_服务器.apppy而不是dev_应用服务器.py. 在
可能是因为谷歌的数据存储索引还没有更新。稍等一会儿,它应该可以工作了。谷歌对此进行了解释here
相关问题 更多 >
编程相关推荐