我在Windows Vista 64位上運行Python.org版本2.7 64位以使用Scrapy。我有一些代碼在我通過Command Shell運行時運行(除了一些Command Shell沒有識別非Unicode字符的問題),但是當我嘗試通過Python IDLE運行腳本時,我收到以下錯誤消息:Python Shell未運行Scrapy
Warning (from warnings module):
File "C:\Python27\mrscrap\mrscrap\spiders\test.py", line 24
class MySpider(BaseSpider):
ScrapyDeprecationWarning: __main__.MySpider inherits from deprecated class scrapy.spider.BaseSpider, please inherit from scrapy.spider.Spider. (warning only on first subclass, there may be others)
用來生成該錯誤代碼是:
from scrapy.spider import BaseSpider
from scrapy.selector import Selector
from scrapy.utils.markup import remove_tags
import re
class MySpider(BaseSpider):
name = "wiki"
allowed_domains = ["wikipedia.org"]
start_urls = ["http://en.wikipedia.org/wiki/Asia"]
def parse(self, response):
titles = response.selector.xpath("normalize-space(//title)")
for titles in titles:
body = response.xpath("//p").extract()
body2 = "".join(body)
print remove_tags(body2)
首先,這是什麼錯誤,當它工作正常在命令外殼的原因是什麼?其次,當我按照錯誤中的指示並用「Spider」代替代碼中的BaseSpider的兩個實例時,代碼將在Python shell中運行,但什麼也不做。沒有錯誤,沒有打印到日誌,沒有錯誤或警告,什麼都沒有。
誰能告訴我爲什麼這個修訂版本的代碼不打印它的輸出到Python IDLE?
感謝
而不是scrapy.spider import BaseSpider do'from scrapy.spider import Spider' – Jordan
@Jordan我已經這樣做了。當我做它不再錯誤,但只是沒有做任何事情。 – gdogg371
這是你的全部代碼嗎? –