sitemap.xml ファイルから投稿を取得する必要があります。sitemap.xml ファイルは、他のサイトマップ ファイルを指します。私のスパイダーは次のとおりで、メインのサイトマップ ファイルが指すサイトマップの 1 つで正常に動作します。
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>