Python 包括非HTML项目的Scrapy爬网站点

Python 包括非HTML项目的Scrapy爬网站点,python,web-crawler,scrapy,scrapy-spider,Python,Web Crawler,Scrapy,Scrapy Spider,我使用Scrapy来抓取整个网站,包括图像、CSS、JavaScript和外部链接。我注意到Scrapy的默认CrawlSpider只处理HTML响应,而忽略外部链接。因此,我尝试重写方法\u requests\u follow,并在开始时删除检查,但没有成功。我还尝试使用方法process\u request来允许所有请求,但也失败了。这是我的密码: class MySpider(CrawlSpider): name = 'myspider' allowed_domains =

我使用Scrapy来抓取整个网站,包括图像、CSS、JavaScript和外部链接。我注意到Scrapy的默认
CrawlSpider
只处理HTML响应,而忽略外部链接。因此,我尝试重写方法
\u requests\u follow
,并在开始时删除检查,但没有成功。我还尝试使用方法
process\u request
来允许所有请求,但也失败了。这是我的密码:

class MySpider(CrawlSpider):
    name = 'myspider'
    allowed_domains = ['example.com']
    start_urls = ['http://example.com']

    rules = (Rule(LinkExtractor(), callback='parse_item', follow=False,
                  process_request='process_request'),)

    def parse_item(self, response):
        node = Node()
        node['location'] = response.url
        node['content_type'] = response.headers['Content-Type']
        yield node

        link = Link()
        link['source'] = response.request.headers['Referer']
        link['destination'] = response.url
        yield link

    def process_request(self, request):
        # Allow everything
        return request

    def _requests_to_follow(self, response):
        # There used to be a check for Scrapy's HtmlResponse response here
        seen = set()
        for n, rule in enumerate(self._rules):
            links = [l for l in rule.link_extractor.extract_links(response) if l not in seen]
            if links and rule.process_links:
                links = rule.process_links(links)
            for link in links:
                seen.add(link)
                r = Request(url=link.url, callback=self._response_downloaded)
                r.meta.update(rule=n, link_text=link.text)
                yield rule.process_request(r)
其思想是构建一个域图,这就是为什么我的
parse_项
生成一个
节点
对象,其中包含资源的位置和类型,以及一个
链接
对象来跟踪节点之间的关系。外部页面应该检索其节点和链接信息,但当然不应该对其进行爬网


提前感谢您的帮助。

据我所知,对于这种类型的爬行,可能更适合。查看pyspider的文档,如果可能的话,我宁愿使用Scrapy。。。