title: Stop Scrapy after N items scraped
body: <p>I'm having trouble with Scrapy.  I need code that will scrap up to 1000 internal links per given url.  My code works when run at command line, but the spider doesn't stop, only receives the message.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
  from scrapy.contrib.spiders import CrawlSpider, Rule
  from scrapy.item import Item, Field
  from scrapy.contrib.closespider import CloseSpider
  
  class MyItem(Item):
      url= Field()
  
  class MySpider(CrawlSpider):
      name = 'testspider1'
      allowed_domains = ['angieslist.com']
      start_urls = ['http://www.angieslist.com']
  
      rules = (Rule(SgmlLinkExtractor(), callback='parse_url', follow=True), )
  
      def parse_url(self, response):
          item = MyItem()
          item['url'] = response.url
  
          scrape_count = self.crawler.stats.get_value('item_scraped_count')
          print scrape_count
  
          limit = 10
  
          if scrape_count == limit:
              raise CloseSpider('Limit Reached')
  
          return item
  </code></pre>