Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Scrapy从两个级别的sitemap.xml获取链接_Python_Scrapy_Sitemap_Scrapy Spider - Fatal编程技术网

Python 使用Scrapy从两个级别的sitemap.xml获取链接

Python 使用Scrapy从两个级别的sitemap.xml获取链接,python,scrapy,sitemap,scrapy-spider,Python,Scrapy,Sitemap,Scrapy Spider,我需要从sitemap.xml文件中获取帖子。xml文件指向其他站点地图文件。我的spider如下所示,它可以很好地处理主站点地图文件指向的一个站点地图 class MySpider(SitemapSpider): name = "example" allowed_domains = ['www.example.com'] sitemap_urls = ["http://sitemaps.example.com/post-sitemap1.xml"] sitem

我需要从sitemap.xml文件中获取帖子。xml文件指向其他站点地图文件。我的spider如下所示,它可以很好地处理主站点地图文件指向的一个站点地图

class MySpider(SitemapSpider):
    name = "example"
    allowed_domains = ['www.example.com']

    sitemap_urls = ["http://sitemaps.example.com/post-sitemap1.xml"]
    sitemap_rules = [('\d{4}/\d{2}/\d{2}/\w+', 'parse_post')]

    def parse_post(self, response):
        item = PostItem()
        item['url'] = response.url
        return item
我怎样才能使爬行器跟随主站点地图文件指向的站点地图文件? 主站点地图文件如下所示:

<sitemapindex>
    <sitemap>
        <loc>http://sitemaps.example.com/sitemap_recent.xml</loc>               
        <lastmod>2014-09-14T02:15:32-04:00</lastmod></sitemap>
    <sitemap>
        <loc>http://sitemaps.example.com/post-sitemap1.xml</loc>
         <lastmod>2014-09-14T02:15:32-04:00</lastmod></sitemap>  
    </sitemap>
    <sitemap>
          <loc>http://sitemaps.example.com/post-sitemap2.xml</loc>

          <lastmod>2014-02-10T22:50:43-05:00</lastmod>
    </sitemap> 
</sitemapindex>

http://sitemaps.example.com/sitemap_recent.xml               
2014-09-14T02:15:32-04:00
http://sitemaps.example.com/post-sitemap1.xml
2014-09-14T02:15:32-04:00
http://sitemaps.example.com/post-sitemap2.xml
2014-02-10T22:50:43-05:00

默认情况下,
SitemapSpider
应该执行您想要的操作。你有没有试过用最新版本的Scrapy?