我試圖把一些網站我爬到擱置,但擱置不會接受任何網站對象。它會接受列表,字符串,元組,你有什麼,但只要我把一個Site對象,它崩潰時,我試圖獲得擱置的內容擱置給出奇怪的錯誤
所以,當我填滿我這樣的擱置:
def add_to_shelve(self, site):
db = shelve.open("database")
print site, site.url
for word in site.content:
db[word] = site.url #site.url is a string, word has to be one too
shelve.open("database")['whatever']
完美地工作。
但是,如果我這樣做:
def add_to_shelve(self, site):
db = shelve.open("database")
print site, site.url
for word in site.content:
db[word] = site #site is now an object of Site
shelve.open("database")['whatever']
錯誤出與此錯誤消息:
AttributeError: 'module' object has no attribute 'Site'
我完全難住了,和PYTHONDOCS,奇怪的是,沒有太多的信息無論是。他們說的是,貨架上的鑰匙必須是一個字符串,但價值或數據可以是「任意物體」