擅长:python、mysql、java
<p>您需要添加站点地图规则来处理已爬网URL中的数据,并且可以创建任意数量的站点地图规则。
例如,假设您有一个名为<a href="http://www.xyz.nl//x/" rel="nofollow">http://www.xyz.nl//x/</a>的页面,您希望创建一个规则:</p>
<pre><code>class MySpider(SitemapSpider):
name = 'xyz'
sitemap_urls = 'http://www.xyz.nl/sitemap.xml'
# list with tuples - this example contains one page
sitemap_rules = [('/x/', parse_x)]
def parse_x(self, response):
sel = Selector(response)
paragraph = sel.xpath('//p').extract()
return paragraph
</code></pre>