Scrapy笔记: 一 安装:

  1. pip3 install wheel

    1. pip3 install lxml

      1. pip3 install pyopenssl

      2. pip3 install -i https://mirrors.aliyun.com/pypi/simple/ pypiwin32

      3. 下载文件(twisted): https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted pip3 install 文件路径\Twisted-19.2.0-cp36-cp36m-win_amd64.whl 6.pip3 install scrapy 7.scrapy 测试安装是否成功 Scrapy 1.6.0 - no active project ...

二 scrapy命令 全局(所有路径下都可以使用): bench Run quick benchmark test fetch Fetch a URL using the Scrapy downloader

      # 会把爬虫程序创建在当前目录下
    genspider     Generate new spider using pre-defined templates
​
    # 可以在当前目录下启动爬虫程序
    runspider     Run a self-contained spider (without creating a project)
​
    runspider 爬虫程序的绝对路径
​
    settings     Get settings values
    shell         Interactive scraping console
​
    # 创建scrapy项目
    startproject Create new project
    version       Print Scrapy version
    view
​
局部(在scrapy项目中可以使用):
    bench         Run quick benchmark test
    # 监测语法
    check         Check spider contracts
    # 根据爬虫程序的name 启动爬虫程序
    crawl         Run a spider
​
    # !!!!!!!重点使用它!!!!!!!
    scrapy crawl name
​
    edit         Edit spider
    fetch         Fetch a URL using the Scrapy downloader
    genspider     Generate new spider using pre-defined templates
    # 查看所有的爬虫程序
    list         List available spiders
​
    parse         Parse URL (using its spider) and print the results
​
    runspider     Run a self-contained spider (without creating a project)
​
    settings     Get settings values
    shell         Interactive scraping console
    startproject Create new project
    version       Print Scrapy version
    view         Open URL in browser, as seen by Scrapy

三 创建scrapy项目 Django: # 创建项目 django-admin startproject P1 cd P1

    # 创建实例
  python3 manage.py app01
  python3 manage.py bbs
Scrapy:
  # 创建项目
  scrapy startproject spider_project
  cd spider_project
​
  # 创建爬虫程序
  scrapy genspider chouti chouti.com
​
  # 执行爬虫程序
  scrapy crawl chouti
​
  # 取消日志
  scrapy crawl --nolog chouti
​
settings:
  # 不遵循反爬协议
  ROBOTSTXT_OBEY = False
main.py
  from scrapy.cmdline import execute
  # execute(['scrapy', 'crawl', 'baidu'])
  execute("scrapy crawl --nolog chouti".split(' '))
main.py
  from scrapy.cmdline import execute
  # execute(['scrapy', 'crawl', 'baidu'])
  execute("scrapy crawl --nolog chouti".split(' '))
Spiders.chouti.py
​
  class ChoutiSpider(scrapy.Spider):
      def parse(self, response):
      def parse_user_index(self, response):
items.py
  # 新闻items类
  class SpiderNewListItem(scrapy.Item):
      # define the fields for your item here like:
      # 新闻链接
      new_url = scrapy.Field()
      # 新闻文本
      new_text = scrapy.Field()
      # 点赞数
      nice_num = scrapy.Field()
      # 新闻ID
      new_id = scrapy.Field()
      # 评论数
      commit_num = scrapy.Field()
      # 新闻详情
      new_content = scrapy.Field()
      # 发表新闻用户的主页
      user_link = scrapy.Field()
    # 新闻items类
  class SpiderUserListItem(scrapy.Item):
      # define the fields for your item here like:
      # 新闻链接
      new_url = scrapy.Field()
      # 新闻文本
      new_text = scrapy.Field()
      # 点赞数
      nice_num = scrapy.Field()
      # 新闻ID
      new_id = scrapy.Field()
      # 评论数
      commit_num = scrapy.Field()
      # 新闻详情
      new_content = scrapy.Field()
      # 用户名
      user_name = scrapy.Field()
​
pipelines.py
​
  class SpiderNewListPipeline(object):
      def __init__(self, ip, port, mongo_db):
          self.ip = ip
          self.port = port
          self.mongo_db = mongo_db
    # 必须配置才可以启动ITEM_PIPELINES
  ITEM_PIPELINES = {
      'spider_project.pipelines.SpiderNewListPipeline': 300,
      'spider_project.pipelines.SpiderUserListPipeline': 301,
  }
​
  # MongoDB配置信息
  IP = 'localhost'
  PORT = 27017
  DB = 'chouti'

浅谈scrapy框架安装使用的更多相关文章

  1. Python爬虫进阶三之Scrapy框架安装配置

    初级的爬虫我们利用urllib和urllib2库以及正则表达式就可以完成了,不过还有更加强大的工具,爬虫框架Scrapy,这安装过程也是煞费苦心哪,在此整理如下. Windows 平台: 我的系统是 ...

  2. Python爬虫进阶之Scrapy框架安装配置

    Python爬虫进阶之Scrapy框架安装配置 初级的爬虫我们利用urllib和urllib2库以及正则表达式就可以完成了,不过还有更加强大的工具,爬虫框架Scrapy,这安装过程也是煞费苦心哪,在此 ...

  3. 手撸ORM浅谈ORM框架之基础篇

    好奇害死猫 一直觉得ORM框架好用.功能强大集众多优点于一身,当然ORM并非完美无缺,任何事物优缺点并存!我曾一度认为以为使用了ORM框架根本不需要关注Sql语句如何执行的,更不用关心优化的问题!!! ...

  4. 手撸ORM浅谈ORM框架之Add篇

    快速传送 手撸ORM浅谈ORM框架之基础篇 手撸ORM浅谈ORM框架之Add篇 手撸ORM浅谈ORM框架之Update篇 手撸ORM浅谈ORM框架之Delete篇 手撸ORM浅谈ORM框架之Query ...

  5. 手撸ORM浅谈ORM框架之Update篇

    快速传送 手撸ORM浅谈ORM框架之基础篇 手撸ORM浅谈ORM框架之Add篇 手撸ORM浅谈ORM框架之Update篇 手撸ORM浅谈ORM框架之Delete篇 手撸ORM浅谈ORM框架之Query ...

  6. 手撸ORM浅谈ORM框架之Delete篇

    快速传送 手撸ORM浅谈ORM框架之基础篇 手撸ORM浅谈ORM框架之Add篇 手撸ORM浅谈ORM框架之Update篇 手撸ORM浅谈ORM框架之Delete篇 手撸ORM浅谈ORM框架之Query ...

  7. 手撸ORM浅谈ORM框架之Query篇

    快速传送 手撸ORM浅谈ORM框架之基础篇 手撸ORM浅谈ORM框架之Add篇 手撸ORM浅谈ORM框架之Update篇 手撸ORM浅谈ORM框架之Delete篇 手撸ORM浅谈ORM框架之Query ...

  8. Scrapy 框架 安装 五大核心组件 settings 配置 管道存储

    scrapy 框架的使用 博客: https://www.cnblogs.com/bobo-zhang/p/10561617.html 安装: pip install wheel 下载 Twisted ...

  9. Scrapy 框架 安装

    Scrapy 框架 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架,用途非常广泛. 框架的力量,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网页 ...

随机推荐

  1. 远程桌面连接,运维工程师-必备软件【MultiDesk】

    实习时,在本地一家大型女装公司做桌面运维,服务器碰得到少,大部分时间都是在维护同事的电脑桌面,什么360全家桶了,毒霸了,都是通过远程工具 teamviewer 去搞定的. 后来做了前端开发,免不了自 ...

  2. Centos7.4 离线安装httpd(解决rpm依赖)

    1.直接下载httpd的rpm安装包,安装失败需要先解决依赖. [root@node06 ~]# rpm -ivh httpd--.el7.centos.x86_64.rpm warning: htt ...

  3. php nl2br()函数 语法

    php nl2br()函数 语法 作用:在字符串中的新行(\n)之前插入换行符dd马达 语法:nl2br(string,xhtml) 参数: 参数 描述 string 必须.规定要检查的字符串. xh ...

  4. 【Linux】设置开机自启

    忘记转发的哪里的. 方法 1这种方法会利用 /etc/ 中的 rc.local 文件来在启动时执行脚本与命令.我们在文件中加上一行来执行脚本,这样每次启动系统时,都会执行该脚本. 不过我们首先需要为 ...

  5. 安装uWebSocketIO

    https://github.com/uNetworking/uWebSockets sudo apt-get install libuv1-dev git clone https://github. ...

  6. cannot access Input/output error

    ls: cannot access  Input/output errorls: cannot open directory .: Input/output error 硬盘故障,只读或只写,你可以d ...

  7. nginx中如何设置gzip(总结)

    nginx中如何设置gzip(总结) 一.总结 一句话总结: 真正用的时候,花一小点时间把gzip的各个字段的意思都看一下,会节约大量时间 直接gzip on:在nginx的配置中就可以开启gzip压 ...

  8. 部署Jenkins完整记录

    Jenkins通过脚本任务触发,实现代码的自动化分发,是CI持续化集成环境中不可缺少的一个环节.下面对Jenkins环境的部署做一记录.-------------------------------- ...

  9. 九. jenkins用户权限管理

    由于jenkins默认的权限管理体系不支持用户组和角色的配置,所以需要使用第三方插件来支持角色的配置: Role-based Authorization Strategy 1.先安装插件,如下: 2. ...

  10. phpstorm中sass编译时目录或内容包含中文字符报错

    ruby版本:ruby 2.4.1p111 (2017-03-22 revision 58053) [x64-mingw32] sass版本:Sass 3.4.24 (Selective Steve) ...