现在shell里面
scrapy startproject tutorial
然后
cd tutorial
scrapy genspider quotes quotes.toscrape.com
观察原始页面发现数据存储在3个内容里面
text
author
tags
然后修改Items.py
# -*- coding: utf-8 -*- # Define here the models for your scraped items # # See documentation in: # https://doc.scrapy.org/en/latest/topics/items.html import scrapy class QuoteItem(scrapy.Item):
text= scrapy.Field()
author=scrapy.Field()
tags= scrapy.Field()
def parse(self, response):
quotes = response.css('.quote')
for quote in quotes:
text = quote.css('.text::text').extract_first()
author = quote.css('.author::text').extract_first()
tags = quote.css('.tags .tga::text').extract()