Scrapy 简单操作

 现在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()
      
 

猜你喜欢

转载自www.cnblogs.com/zj0724/p/9124756.html