《零基础入门学习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 \ -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

相关推荐
Cha0DD2 小时前
【由浅入深探究langchain】第二十集-SQL Agent+Human-in-the-loop
人工智能·python·ai·langchain
Cha0DD2 小时前
【由浅入深探究langchain】第十九集-官方的SQL Agent示例
人工智能·python·ai·langchain
智算菩萨4 小时前
【Tkinter】4 Tkinter Entry 输入框控件深度解析:数据验证、密码输入与现代表单设计实战
python·ui·tkinter·数据验证·entry·输入框
七夜zippoe4 小时前
可解释AI:构建可信的机器学习系统——反事实解释与概念激活实战
人工智能·python·机器学习·可解释性·概念激活
YuanDaima20487 小时前
[CrewAI] 第15课|构建一个多代理系统来实现自动化简历定制和面试准备
人工智能·python·面试·agent·crewai
WHS-_-20227 小时前
Python 算法题学习笔记一
python·学习·算法
码界筑梦坊8 小时前
353-基于Python的大湾区气候数据可视化分析系统
开发语言·python·信息可视化·数据分析·django·vue·毕业设计
如何原谅奋力过但无声8 小时前
【chap11-动态规划(上 - 基础题目&背包问题)】用Python3刷《代码随想录》
数据结构·python·算法·动态规划
云姜.8 小时前
JSON Schema使用
python·json
Sunshine for you9 小时前
使用Flask快速搭建轻量级Web应用
jvm·数据库·python