0

我对 Scrapy 很陌生。在这里我的蜘蛛要爬twistedweb。

class TwistedWebSpider(BaseSpider):

    name = "twistedweb3"
    allowed_domains = ["twistedmatrix.com"]
    start_urls = [
        "http://twistedmatrix.com/documents/current/web/howto/",
    ]
    rules = (
        Rule(SgmlLinkExtractor(),
            'parse',
            follow=True,
        ),
    )
    def parse(self, response):
        print response.url
        filename = response.url.split("/")[-1]
        filename = filename or "index.html"
        open(filename, 'wb').write(response.body)

当我运行时 scrapy-ctl.py crawl twistedweb3,它只获取。

获取index.html内容,我尝试使用SgmlLinkExtractor,它按我的预期提取链接,但无法遵循这些链接。

你能告诉我哪里出错了吗?

假设我想获取 css、javascript 文件。我如何实现这一目标?我的意思是获得完整的网站?

4

1 回答 1

4

rules属性属于CrawlSpider.Use class MySpider(CrawlSpider)。此外,当你使用时,CrawlSpider你不能覆盖parse方法,而是使用parse_response或其他类似的名称。

于 2010-08-19T04:58:53.890 回答