item.py
python-*- coding: utf-8 -*
import scrapy
class BokeItem(scrapy.Item):
url=scrapy.Field()
title=scrapy.Field()
content=scrapy.Field()
boke_spider.py
python-*- coding: utf-8 -*-
from scrapy.contrib.spiders import CrawlSpider ,Rule
from scrapy.contrib.linkextractors import LinkExtractor
from boke.items import BokeItem
class BokeItem(CrawlSpider):
name = 'blog'
start_urls =['http://blog.sina.com.cn/s/blog_4701280b0102eo83.html']
def parse_torrent(self,response):
torrent=BokeItem()
torrent['url']=response.url
torrent['title']=response.xpath("//h2[@class='titName SG_txta']/text()").extract()[0]
torrent['content']=response.xpath("//div[@style='min-height:22px']/text()").extract()[0]
return torrent
3 回答
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
from scrapy.contrib.spiders import CrawlSpider ,Rule
你调用的是CrawlSpider
类,但是显然没有写任何的规则
建议改为Spider
类,并将parse_torrent
改名为parse
,如下:
from scrapy.contrib.spiders import Spider
from boke.items import BokeItem
class BokeItem(Spider):
添加回答
举报
0/150
提交
取消