《零基础入门学习Python》第062讲:论一只爬虫的自我修养10:安装Scrapy

这节课我们来谈谈 Scrapy

说到Python爬虫,大牛们都会不约而同地提起Scrapy。因为Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中。

Scrapy最初是为了页面抓取(更确切来说, 网络抓取)所设计的,也可以应用在获取API所返回的数据(例如Amazon Associates Web Services)或者通用的网络爬虫。

这节课主要讲解如何安装 Scrapy

  • 使用的电脑系统:Windows 10 64位
  • 使用的Python的版本:python 3.5.2

step1:安装Python 3.5.2

直接下载安装包安装即可,在安装时,必须勾选 Add Python 3.5 to PATH,这是将 python 添加到 PATH 环境变量。

如果在安装时没有勾选,也没关系,打开"运行",输入cmd。执行以下命令,设置环境变量:

C:\Python35\python.exe C:\Python35\tools\Scripts\win_add2path.py

step2 :确认Python 安装正确

重新打开cmd,输入命令"python --version"

--如果有显示Python2.7.9则说明成功;

--如果没有,请服用Windows特效药:重启系统尝试一下。

step3:安装pywin32(32位版本)

这里有两种办法安装:

法1:进入网页http://sourceforge.net/projects/pywin32/,下载pywin32,双击安装。

法2:打开cmd,输入命令 pip install pywin32,等待安装成功即可。

如果不能成功的话,可能就是没有安装 pip(如果你是使用Python2.9 以前的版本,是需要自己另外安装pip的,步骤如下:)

下面的内容针对 没有 pip 的用户,其他的人可以直接看step4。

•安装pip,地址:

--pip · PyPI

a)下载get-pip.py

b)进入cmd,执行:python get-pip.py

c)检查Python27\Scripts中是否有pip.exe并设置Python27\Scripts到环境变量中

d)重启cmd,输入命令"pip --version"

•如果有显示版本号则说明成功;

•如果没有,请继续服用Windows特效药:重启系统尝试一下。

step4:安装 lxml

这里也可以使用两种办法安装:

法1:进入网页Installing lxml,下载 lxml,双击安装。

法2:打开cmd,输入命令 pip install lxml,等待安装成功即可。

step5:安装OpenSSL

法1:pypi.python.org/pypi/pyOpenSSL

法2:pip install pyOpenSSL

step6:安装Scrapy

pip install Scrapy

这样就安装 OK了,我们班来验证一下:

重新打开cmd,输入命令 Scrapy

C:\Users\XiangyangDai>Scrapy

:0: UserWarning: You do not have a working installation of the service_identity module: 'cannot import name 'opentype''. Please install it from <https://pypi.python.org/pypi/service_identity\> and make sure all of its dependencies are satisfied. Without the service_identity module, Twisted can perform only rudimentary TLS client hostname verification. Many valid certificate/hostname mappings may be rejected.

Scrapy 1.5.1 - no active project

Usage:

scrapy <command> options args

Available commands:

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)

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

more More commands available when run from project directory

Use "scrapy <command> -h" to see more info about a command

没问题了,但是这里出现了一个 warning,说的是 service_identity 模块里的 opentype 用不了,这就尴尬了,我们尝试重新安装 service_identity 试一下:

先卸载 service_identity

输入:pip uninstall service_identity

等待卸载完成,再安装 service_identity

输入:pip install service_identity

再来验证一下:输入 Scrapy

完美了。

其实上面的卸载安装命令可以改为一条命令即可:pip install -I -U service_identity

相关推荐
timeDifference₇7 小时前
Python Vibe Coding实操实验报告
开发语言·jvm·python
geovindu8 小时前
python:DecisionTree
开发语言·后端·python·算法
怒放的生命19919 小时前
代码知识库 RAG 问答系统 —— 从 0 到 1 实现教程
python·状态模式·fastapi·全栈开发·ai agent应用开发
geovindu10 小时前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
fengkai454510 小时前
Python运维
运维·python·监控·psutil·ipy
Fancy.76111 小时前
:Python条件与循环语句学习总结
python
Wellijohn12 小时前
Python 容器选型实测:list.insert(0) 慢 925 倍,in 慢 6000 倍
python
新*12 小时前
标题全变成一级?靠编号规律找回章节边界
python·正则表达式·pdf解析·文本处理
高洁0115 小时前
多源数据融合:把零散信号拼成一致图景
人工智能·python·机器学习·transformer·迁移学习
郝学胜-神的一滴15 小时前
Effective Python 条款41:试Mix‑In组合式开发
开发语言·pytorch·python·pycharm·numpy