|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是item.py
- # -*- coding: utf-8 -*-
- # Define here the models for your scraped items
- #
- # See documentation in:
- # http://doc.scrapy.org/en/latest/topics/items.html
- import scrapy
- class DemoItem(scrapy.Item):
- # define the fields for your item here like:
- # name = scrapy.Field()
- price = scrapy.Field()
- title = scrapy.Field()
复制代码
这是DemoSpider.py文件
- import scrapy
- from Demo.items import DemoItem
- class Demo_spider(scrapy.Spider):
- name = 'zufang'
- start_urls = ["http://nn.ganji.com/fang1/"]
- def parse(self, response):
- sites = response.xpath(".//div[@class='f-list-item ']/dl")
- items = []
- for site in sites:
- item = DemoItem()
- item['price'] = site.xpath("dd[5]/div[1]/span[1]/text()").extract()
- item['title'] = site.xpath("dd[1]/a/text()").extract()
- items.append(item)
-
- return items
复制代码
按照小甲鱼老师的scrapy crawl zufang -o items.json -t json格式输出
然后得到
我想问的是title: 输出的为什么不是文字呢?现在输出的是什么?我愿望想得到的是价格和标题的爬取的
|
|