Scrapy入门级简单整理

  1. 安装scrapy
pip install scrapy

  • 1

安装完成 scrapy 提供一整套 scrapy 命令

若pip安装失败,可到http://www.lfd.uci.edu/~gohlke/pythonlibs/网站找对应的twisted和scrapy的whl包进行下载Scrapy入门级简单整理
通过下面命令进行安装,先装twisted,再装scrapy

pip install xxx.whl

  • 1
  1. 使用 scrapy 命令行创建项目
scrapy startproject 项目名称

  • 1
  1. 创建爬虫
cd 项目目录
scrapy genspider 爬虫名称 域名

如果需要使用crawlspider 等模板
scrapy genspider -t 模板名 爬虫文件名 域名

  • 1
  • 2
  • 3
  • 4
  • 5
  1. 编写代码
    4.1 编写模型代码
    4.2 编写爬虫代码
    4.3 编写管道代码

  2. 运行爬虫
    注意:必须在工程目录下

scrapy crawl 爬虫名称

  • 1

若运行时报错:no module named win32api,执行下面代码

pip install pypiwin32

  • 1
© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...