想要使用Python从特定网站获取数据以上传到Google App Engine。这个想法是创建一个数据库数据来存储服务器上的信息,以检索并显示在Web应用程序中。使用Python从网页获取数据
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
import os
import datetime
from google.appengine.ext.webapp import template
# A class which creates all the pokemon on the server
class Pokemondata(db.Model):
number = db.IntegerProperty()
pokemonname = db.StringProperty()
description = db.StringProperty()
newpoke = Pokemondata(number="001",pokemonname="Balbasuar",description="The grass pokemon")
newpoke = Pokemondata(number="002",pokemonname="Ivysaur",description="The seed pokemon")
newpoke = Pokemondata(number="003",pokemonname="Venasaur",description="Another grass pokemon")
newpoke.put()
# A class to put new pokemon in to the server ?
class ApplyHandler(webapp.RequestHandler):
def post(self):
self.session = Session()
pnumber = self.request.get('number')
pname = self.request.get('pokemonname')
pdescription = self.request.get('description')
newpoke = Pokemondata(number=pnumber,pokemonname=pname,description=pdescription)
newpoke.put()
self.session['pokemon'] = pname
doRender(self,"board.htm",{})
# Construct a google table for this data
# to display
class JSONInterface(webapp.RequestHandler):
def get(self):
que = db.Query(Pokemondata)
listing = que.fetch(limit = 12)
doRender(self,'http://pokedexapp.appspot.com/[email protected]#input',
{'listing':listing})
application = webapp.WSGIApplication([('/(.*html)?', ApplyHandler),
('/json', JSONInterface)], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
当我部署应用程序来测试我得到服务器错误。任何人都可以告诉我这是否是正确方向的一步,需要修改哪些内容?
YAML的文件是目前
应用:pokedexapp 版本:1 运行:蟒蛇 API_VERSION:1
处理程序: - 网址:/.* 脚本:main.py
我明白代码缩进是错误的。我目前正在尝试修复它 – user2045126 2013-05-03 02:55:06
你想发布你得到的错误。 – dragonx 2013-05-03 03:35:57
你可以发布.yaml文件吗?我在这里看到一些错误,在处理程序中使用的MainHandler,JSONInterface,SearchResult类在哪里? – marcadian 2013-05-03 05:27:52