spider的代码
from textsc.items import TextscItem
from scrapy.selector import Selector
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors import LinkExtractor
class Baispider(CrawlSpider):
name = "Baidu"
allowed_domains = ["baidu.com"]
start_urls = [
"https://zhidao.baidu.com/list"
]
rules = (
Rule(LinkExtractor(allow=('/shop', ), deny=('fr', )), callback='parse_item'),
)
def parse_item(self, response):
sel= Selector(response)
items=[]
item=TextscItem()
title=sel.xpath('//div[@class="shop-menu"]/ul/li/a/text()').extract()
for i in title:
items.append(i)
item['TitleName'] = items
print (item['TitleName'])
return item
item.py的代码
import scrapy
import json
class TextscItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
TitleName = scrapy.Field()
pass
运行时输入了
scrapy crawl Bai -o items.json -t json
运行时很正常 没报错
但是运行后点击查看了 items.json文件
什么都没有
求解决方法
谢过.