我用Bottle做了一个简单的程序。然而,我遇到了一个错误;
@route('/login')
def login_form():
return '''<form method="POST" action="/login">
What do you want to search for?<br>
<input name="search" type="text" />
<input type="submit" />
</form>'''
@route('/login', method='POST')
def PeopleSearch():
raw = request.forms.get('search')
query = urllib.urlencode ( { 'q' : 'who is '+raw } )
response = urllib.urlopen ( 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&' + query ).read()
json = m_json.loads ( response )
results = json [ 'responseData' ] [ 'results' ]
for result in results :
url = result['url']
return (url)
进口是:
# -*- coding: cp1252 -*-
import codecs
from bottle import route, run, template, request
import Tkinter
from Tkinter import *
import turtle
import time
from xgoogle.search import GoogleSearch, SearchError
import urllib2
import urllib
import json as m_json
import sys
from urllib import FancyURLopener
import time
from BeautifulSoup import BeautifulSoup
import json as simplejson
Soup = BeautifulSoup
from nltk import sent_tokenize, word_tokenize
from collections import Counter
from math import log10
# -*- coding: utf-8 *-*
现在这个程序应该返回 url,但它没有。它也抛出了我之前提到的错误。当我不在网页上运行它时,它工作得很好。