scrapy教程

目录

前言

scrapy现在已经在我们的”雅典娜”系统中使用, 它是一个开源的由python编写的成熟的爬虫框架, git地址scrapy

需要掌握的技术和工具

  1. 爬虫相关知识(爬虫反爬虫)
  2. xpath语法, css选择器语法
  3. scrapy
  4. Bloom Filter
  5. python-rq
  6. redis或mongodb

安装scrapy

这里在ubuntu上安装
1. 首先安装python, 版本2.7.3
2. sudo apt-get install python-dev
3. sudo apt-get install libevent-dev
4. pip install Scrapy

入门案例: 从w3school.com.cn开始

  1. 建立项目: scrapy startproject w3school
  2. 编写Item: 编辑items.py
    import scrapy
    from scrapy.item import Item,Field
    
    
    class W3SchoolItem(scrapy.Item):
        # define the fields for your item here like:
        # name = scrapy.Field()
        title = Field()
        link = Field()  
        desc = Field()