Python 使用Scrapy从两个级别的sitemap.xml获取链接
我需要从sitemap.xml文件中获取帖子。xml文件指向其他站点地图文件。我的spider如下所示,它可以很好地处理主站点地图文件指向的一个站点地图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
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?