Python Scrapy-无法爬行

Python Scrapy-无法爬行,python,scrapy,web-crawler,Python,Scrapy,Web Crawler,我正在尝试用scrapy抓取一些网站。下面是一个示例代码。未调用方法parse。我试图通过反应堆服务运行代码(提供的代码)。所以,我从startCrawling.py运行它,它有反应堆。我知道我错过了什么。你能帮忙吗 谢谢 Code-categorization.py from scrapy.contrib.spiders.init import InitSpider from scrapy.http import Request, FormRequest from scrapy.contri

我正在尝试用scrapy抓取一些网站。下面是一个示例代码。未调用方法parse。我试图通过反应堆服务运行代码(提供的代码)。所以,我从startCrawling.py运行它,它有反应堆。我知道我错过了什么。你能帮忙吗

谢谢

Code-categorization.py

from scrapy.contrib.spiders.init import InitSpider
from scrapy.http import Request, FormRequest
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.contrib.spiders import Rule
from scrapy.selector import Selector
from scrapy.selector import HtmlXPathSelector
from items.items import CategorizationItem
from scrapy.contrib.spiders.crawl import CrawlSpider
class TestingSpider(CrawlSpider):
         print 'in spider'
         name = 'testSpider'
         allowed_domains = ['wikipedia.org']
         start_urls = ['http://www.wikipedia.org']
         def parse(self, response):

             # Scrape data from page
             print 'here'
             open('test.html','wb').write(response.body)
代码-startCrawling.py

 from twisted.internet import reactor
 from scrapy.crawler import Crawler
 from scrapy.settings import Settings
 from scrapy import log, signals
 from scrapy.xlib.pydispatch import dispatcher
 from scrapy.utils.project import get_project_settings

 from spiders.categorization import TestingSpider

 # Scrapy spiders script...

 def stop_reactor():
     reactor.stop #@UndefinedVariable    
     print 'hi'

     dispatcher.connect(stop_reactor, signal=signals.spider_closed) 
     spider = TestingSpider()
     crawler = Crawler(Settings())
     crawler.configure()
     crawler.crawl(spider)
     crawler.start()
     reactor.run()#@UndefinedVariable

使用
CrawlSpider
时,不应重写
parse()
方法。您应该在
规则
中使用不同的名称设置自定义
回调。
以下是该报告的摘录:

在编写爬网爬行器规则时,避免使用解析作为回调,因为 爬行爬行器使用解析方法本身来实现其逻辑。 因此,如果重写解析方法,爬网爬行器将不再 工作


非常感谢。我马上接受答案。我会尝试一下,让你知道。有史以来最快的接受,我刚刚点击,它变成了绿色:)