想要使用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