这里爬取的电商网站为当当网的地方特产为例
首先建立爬虫项目
scrapy startproject autop
然后就要编写items文件了
# -*- 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 AutopItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
name=scrapy.Field()#商品名称
price=scrapy.Field()#商品价格
link=scrapy.Field()#商品的链接
comnum=scrapy.Field()#商品的评论数
pipelines的编写
# -*- coding: utf-8 -*-
import codecs
import json
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
class AutopPipeline(object):
def __init__(self):#初始化
self.f=codecs.open(