Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

. Modified the default value of the BOT_NAME setting to the project's name . Modified spider templates to use the already-generated example item instead of a ScrapedItem

elpolilla91eff31f1837
diff --git a/scrapy/trunk/scrapy/command/commands/genspider.py b/scrapy/trunk/scrapy/command/commands/genspider.py
index f897416b7..249a4a30e 100644
--- a/scrapy/trunk/scrapy/command/commands/genspider.py
+++ b/scrapy/trunk/scrapy/command/commands/genspider.py
@@ -54,6 +54,7 @@ class Command(ScrapyCommand):
def _genspider(self, name, site, template_file):
""" Generate spider """
tvars = {
+ 'project_name': settings.get('BOT_NAME'),
'name': name,
'site': site,
'classname': '%sSpider' % ''.join([s.capitalize() for s in name.split('_')])
diff --git a/scrapy/trunk/scrapy/conf/project_template/scrapy_settings.py b/scrapy/trunk/scrapy/conf/project_template/scrapy_settings.py
index c0e60df36..b60eddfe5 100644
--- a/scrapy/trunk/scrapy/conf/project_template/scrapy_settings.py
+++ b/scrapy/trunk/scrapy/conf/project_template/scrapy_settings.py
@@ -4,7 +4,7 @@ import $project_name
# - Scrapy settings for $project_name -
# ---------------------------------------------------------------------------
-BOT_NAME = 'scrapybot'
+BOT_NAME = '$project_name'
BOT_VERSION = '1.0'
SPIDER_MODULES = ['$project_name.spiders']
diff --git a/scrapy/trunk/scrapy/conf/project_template/templates/spider_crawl.tmpl b/scrapy/trunk/scrapy/conf/project_template/templates/spider_crawl.tmpl
index f4a3bd2ed..a45ffdf42 100644
--- a/scrapy/trunk/scrapy/conf/project_template/templates/spider_crawl.tmpl
+++ b/scrapy/trunk/scrapy/conf/project_template/templates/spider_crawl.tmpl
@@ -2,9 +2,9 @@
import re
from scrapy.xpath import HtmlXPathSelector
-from scrapy.item import ScrapedItem
from scrapy.link.extractors import RegexLinkExtractor
from scrapy.contrib.spiders import CrawlSpider, Rule
+from $project_name.items import MyItem
class $classname(CrawlSpider):
domain_name = '$site'
@@ -15,10 +15,11 @@ class $classname(CrawlSpider):
)
def parse_item(self, response):
+ i = MyItem()
#xs = HtmlXPathSelector(response)
- #i = ScrapedItem()
#i.attribute('site_id', xs.x('//input[@id="sid"]/@value'))
#i.attribute('name', xs.x('//div[@id="name"]'))
#i.attribute('description', xs.x('//div[@id="description"]'))
+ return [i]
SPIDER = $classname()
diff --git a/scrapy/trunk/scrapy/conf/project_template/templates/spider_csvfeed.tmpl b/scrapy/trunk/scrapy/conf/project_template/templates/spider_csvfeed.tmpl
index 12b2b7d71..bc96a3de9 100644
--- a/scrapy/trunk/scrapy/conf/project_template/templates/spider_csvfeed.tmpl
+++ b/scrapy/trunk/scrapy/conf/project_template/templates/spider_csvfeed.tmpl
@@ -1,5 +1,6 @@
# -*- coding: utf8 -*-
from scrapy.contrib.spiders import CSVFeedSpider
+from $project_name.items import MyItem
class $classname(CSVFeedSpider):
domain_name = '$site'
@@ -12,12 +13,10 @@ class $classname(CSVFeedSpider):
# return response
def parse_row(self, response, row):
- p = self.create_product(response)
- #p.attribute('site_id', row['id'])
- #p.attribute('supplier', self.domain_name)
- #p.attribute('name', row['name'])
- #p.attribute('description', row['description'])
- #p.attribute('image_urls', row['image_link'])
- return p
+ i = MyItem()
+ #i.attribute('url', row['url'])
+ #i.attribute('name', row['name'])
+ #i.attribute('description', row['description'])
+ return i
SPIDER = $classname()
diff --git a/scrapy/trunk/scrapy/conf/project_template/templates/spider_xmlfeed.tmpl b/scrapy/trunk/scrapy/conf/project_template/templates/spider_xmlfeed.tmpl
index 87b3e10eb..7ea43375e 100644
--- a/scrapy/trunk/scrapy/conf/project_template/templates/spider_xmlfeed.tmpl
+++ b/scrapy/trunk/scrapy/conf/project_template/templates/spider_xmlfeed.tmpl
@@ -1,20 +1,16 @@
# -*- coding: utf8 -*-
from scrapy.contrib.spiders import XMLFeedSpider
+from $project_name.items import MyItem
class $classname(XMLFeedSpider):
domain_name = '$site'
start_urls = ['http://www.$site/feed.xml']
def parse_item(self, response, xSel):
- p = self.create_product(response)
- #p.attribute('url', xSel(''))
- #p.attribute('supplier', self.domain_name)
- #p.attribute('site_id', xSel(''))
- #p.attribute('name', xSel(''))
- #p.attribute('description', xSel(''))
- #p.attribute('image_urls', xSel(''))
- #p.attribute('price', xSel(''))
- #p.attribute('dimensions', xSel(''))
- return p
+ i = MyItem()
+ #i.attribute('url', xSel('url'))
+ #i.attribute('name', xSel('name'))
+ #i.attribute('description', xSel('description'))
+ return i
SPIDER = $classname()