我最近创建了一个api服务器,用于搜索您输入的查询并将其列出。但是在网页上它只列出一个而不是全部。有人可以查看我的代码并帮助我吗?
#!/usr/bin/python
#imports
import os, sys; sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
from pattern.web import Google, Bing, asynchronous, plaintext
from pattern.web import SEARCH
from pattern.server import App
from pattern.server import MINUTE, HOUR, DAY
from pattern.db import date
#variables
app = App("api")
#license keys#############################################################################
Gengine = Google(license="AIzaSyBsfFfxX7IIRC3cG0biFnC_8a4eVbp_DBI", language="en")
Bengine = Bing(license="M92rB8xqUqop9UDWfT9GXIbLSODjkQMYM8mMwjWx398=", language="en")
##########################################################################################
#API Search
@app.route("/search", limit=100, time=HOUR, key=lambda data: app.request.ip)
def Search(q=""):
#print q
for i in range(1, 2):
for result in Gengine.search(q, start=i, count=10, type=SEARCH, cached=True):
print result.title.upper()
print plaintext(result.text) # plaintext() removes all HTML formatting.
print result.url
print result.date
print
title = [result.title]
text = [plaintext(result.text)]
url = [result.url]
date = [result.date]
return {
"title": title,
"text": text
}
app.run("t0mbst0n3", port=8080, threads=100, queue=50)
答案 0 :(得分:1)
return
结束了这个函数,所以你的循环永远不会超过一次迭代。相反,您应该在列表中收集值,然后在函数末尾返回该列表。