弗斯特
错误:
ERROR 2011-04-22 23:25:15,513 __init__.py:395] unbound method put() must be called with Movie instance as first argument (got nothing instead)
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__
handler.get(*groups)
File "C:\Users\Jimenez\workspace\elmovieplace\src\script/crawl.py", line 86, in get
getImdbData(year, findPatGamma, findPatGamma2)
File "C:\Users\Jimenez\workspace\elmovieplace\src\script/crawl.py", line 66, in getImdbData
movie.put()
TypeError: unbound method put() must be called with Movie instance as first argument (got nothing instead)
爬网.py:
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from urllib2 import urlopen
from Classes import Movie
import re
def getImdbData(year, findPatGamma, findPatGamma2):
templistone = []
templisttwo = []
listIterator = []
listIterator[:] = range(len(findPatGamma))
for gi in listIterator:
deltaUrl = findPatGamma[gi]
deltaPage = urlopen(deltaUrl).read()
print deltaUrl
simpleone = (re.findall(re.compile("""id='hmovie'.*[^\n]src='|"(.*[^\n])'|".*[^\n]"""),deltaPage))[0]
templistone.append(simpleone)
simpletwo = (re.findall(re.compile("<title>Project Free TV - (.*) video</title>"),deltaPage))[0]
templisttwo.append(simpletwo)
movie = Movie
url = 'http://www.imdbapi.com/?plot=full&t=' + findPatGamma2[0] + '&y=' + year
imdbPage = urlopen(url).read()
imdbValues, = re.findall(re.compile('{"Title":"(.*)","Year":"(.*)","Rated":"(.*)","Released":"(.*)","Genre":"(.*)","Director":"(.*)","Writer":"(.*)","Actors":"(.*)","Plot":"(.*)","Poster":"(.*)","Runtime":"(.*)","Rating":"(.*)","Votes":"(.*)","ID":"(.*)","Response":"(.*)"}'),imdbPage)
movie.title = imdbValues[0]#done
if imdbValues[1] == 'N/A':
movie.rated = ''
else:
movie.rated = imdbValues[2]#done
if imdbValues[3] == 'N/A':
movie.releaseDate = 'jan 1 1990'
else:
movie.releaseDate = imdbValues[3]
if imdbValues[4] == 'N/A':
movie.tags = [];
else:
movie.tags = re.findall(re.compile('(\w*[^\s|,])'),imdbValues[4])#done
if imdbValues[5] == 'N/A':
movie.diector = ''
else:
movie.director = imdbValues[5],#done
if imdbValues[6] == 'N/A':
movie.writer = ''
else:
movie.writer = imdbValues[6],#done
if imdbValues[7] == 'N/A':
movie.actors = []
else:
movie.actors = re.findall(re.compile('(\w*[^\s|,])'),imdbValues[7])#done
if imdbValues[8] == 'N/A':
movie.description = ''
else:
movie.description = imdbValues[8]#done
if imdbValues[9] == 'N/A':
movie.pic = ''
else:
movie.pic = imdbValues[9]#done
if imdbValues[10] == 'N/A':
movie.length = 0
else:
movie.length = (60 * int((re.findall(re.compile('(.*) hrs .* mins'),imdbValues[10]))[0])) + int((re.findall(re.compile('.* hrs (.*) mins'),imdbValues[10]))[0])#done
movie.uniqueID = imdbValues[13]#done
movie.hostNames = templisttwo
movie.hostUrls = templistone
movie.put()
return
class MyHandler(webapp.RequestHandler):
def get(self):
year = '2011'
betaUrl = 'http://www.free-tv-video-online.me/movies/' + year + '/'
betaPage = urlopen(betaUrl).read()
patFinderBeta = re.compile('<td width="97%" class="mnlcategorylist"><a href="(.*)">')
findPatBeta = re.findall(patFinderBeta,betaPage)
listIteratorBeta = []
listIteratorBeta[:] = range(len(findPatBeta))
for bi in listIteratorBeta:
gammaUrl = betaUrl + findPatBeta[bi]
gammaPage = urlopen(gammaUrl).read()
patFinderGamma = re.compile('<a href="(.*[^\n])" target="_blank" class="mnllinklist">')
findPatGamma = re.findall(patFinderGamma,gammaPage)
patFinderGamma2 = re.compile('<meta name="keywords"content="(.*)">')
findPatGamma2 = re.findall(patFinderGamma2,gammaPage)
getImdbData(year, findPatGamma, findPatGamma2)
ip = self.request.remote_addr
template_values = {
'username': ip,
}
self.response.out.write(template.render('template\crawl.html', template_values))
def main():
app = webapp.WSGIApplication([(r'.*', MyHandler)],debug=True)
wsgiref.handlers.CGIHandler().run(app)
if __name__ == '__main__':
main()
类.py:
from google.appengine.ext import db
class Movie(db.Model):
title = db.StringProperty()
hostNames = db.StringProperty()
hostUrls = db.StringListProperty()
releaseDate = db.DateProperty()
uniqueID = db.StringProperty(default='000000')
playcount = db.IntegerProperty(default='0')
length = db.IntegerProperty()
rated = db.StringProperty()
description = db.StringProperty()
tags = db.StringListProperty()
director = db.StringProperty()
writer = db.StringProperty()
actors = db.StringProperty()
pic = db.StringProperty()
我到处看了一些帖子(换句话说,我已经找了一天了),但我不知道我做错了什么。
“哦”顺便说一句,我的问题没那么明显,我是新来的。
最佳答案
改变它
movie = Movie
到
movie = Movie()
您需要实际创建一个
Movie
类的实例,这就是Movie()
所做的。(错误消息中的关键字是“Movie
instance”。)关于python - 必须以Movie实例作为第一个参数调用未绑定(bind)方法put()的GAE是什么意思,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5761063/