2011-05-15 82 views
-1

我使用scrapy XMLFeedSpider和itertag来循环超过300个Megs XML供稿。scrapy遵循大XML供稿链接

除了将每个条目作为条目保存在该大订阅源中之外,每个条目还具有一些其他链接以进行爬网,这次是链接到html页面。

我知道html页面是使用CrawlerSpider抓取的,因此我试图找到一种方法来跟踪使用这种蜘蛛的大型XML feed的链接。

感谢, 盖伊

回答

2

首先阅读:http://readthedocs.org/docs/scrapy/en/latest/intro/tutorial.html

我创建了scrapy项目。以下是获取该特定XML的所有URL的代码。你应该使用蜘蛛目录。

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
import re 
from scrapy.item import BaseItem 
from scrapy.spider import BaseSpider 
from scrapy.selector import XmlXPathSelector 
from scrapy.utils.spider import create_spider_for_request 
from scrapy.utils.misc import load_object 
from scrapy.utils.response import open_in_browser 

class TestSpider(BaseSpider): 
    name = "test" 
    start_urls = ["http://fgeek.kapsi.fi/test.xml"] 

    def parse(self, response): 
     xpath = XmlXPathSelector(response) 
     count = 0 
     for url in xpath.select('entries/entry/url').extract(): 
      print url 
+0

运行“scrapy crawl projectname”来使用蜘蛛。 – fgeek 2012-01-10 21:43:54