mac安装scrapy并创建项目的实例讲解
最近刚好在学习python+scrapy的爬虫技术,因为mac是自带python2.7的,所以安装3.5版本有两种方法,一种是升级,一种是额外安装3.5版本。
升级就不用说了,讲讲额外安装的版本吧~~~
因为python是有自带版本的,最开始安装的时候都会有一种“会不会冲突”的感觉。
其实安装3.5版本也就是在官网上直接下载之后安装,和普通的mac软件安装方式是一样的~~
https://www.python.org/downloads/release/python-353/
安装完成之后,不会覆盖原来的python,会在/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5文件中
在终端直接输入python会执行python2.7版本
python Python2.7.12(default,Jun292016,14:05:02) [GCC4.2.1CompatibleAppleLLVM7.3.0(clang-703.0.31)]ondarwin Type"help","copyright","credits"or"license"formoreinformation. >>>
在终端直接输入python3则会执行python3.5版本
python3 Python3.5.3(v3.5.3:1880cb95a742,Jan162017,08:49:46) [GCC4.2.1(AppleInc.build5666)(dot3)]ondarwin Type"help","copyright","credits"or"license"formoreinformation. >>>
接下来就可以开始安装scrapy了
python3.5中会自带pip,所以不需要额外安装了,可以直接在终端输入pip3--version查看版本和路径
pip3--version pip9.0.1from/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages(python3.5)
使用pip3安装scrapy
pip3installScrapy
这里的Scrapy一定要首字母大写,不然会在安装的过程中报错~~
Collectingscrapy Retrying(Retry(total=4,connect=None,read=None,redirect=None))afterconnectionbrokenby'NewConnectionError(':Failedtoestablishanewconnection:[Errno61]Connectionrefused',)':/simple/scrapy/ Retrying(Retry(total=3,connect=None,read=None,redirect=None))afterconnectionbrokenby'NewConnectionError(' :Failedtoestablishanewconnection:[Errno61]Connectionrefused',)':/simple/scrapy/ Retrying(Retry(total=2,connect=None,read=None,redirect=None))afterconnectionbrokenby'NewConnectionError(' :Failedtoestablishanewconnection:[Errno61]Connectionrefused',)':/simple/scrapy/ Retrying(Retry(total=1,connect=None,read=None,redirect=None))afterconnectionbrokenby'NewConnectionError(' :Failedtoestablishanewconnection:[Errno61]Connectionrefused',)':/simple/scrapy/ Retrying(Retry(total=0,connect=None,read=None,redirect=None))afterconnectionbrokenby'NewConnectionError(' :Failedtoestablishanewconnection:[Errno61]Connectionrefused',)':/simple/scrapy/ Couldnotfindaversionthatsatisfiestherequirementscrapy(fromversions:) Nomatchingdistributionfoundforscrapy
安装成功之后,可以直接在终端上输入scrapy查看版本号及使用
Scrapy1.4.0-noactiveproject Usage: scrapy[options][args] Availablecommands: benchRunquickbenchmarktest fetchFetchaURLusingtheScrapydownloader genspiderGeneratenewspiderusingpre-definedtemplates runspiderRunaself-containedspider(withoutcreatingaproject) settingsGetsettingsvalues shellInteractivescrapingconsole startprojectCreatenewproject versionPrintScrapyversion viewOpenURLinbrowser,asseenbyScrapy [more]Morecommandsavailablewhenrunfromprojectdirectory Use"scrapy -h"toseemoreinfoaboutacommand
在pycharm中是没有直接创建scrapy项目的,可以使用scrapy命令手动新建项目
scrapystartprojectArticleSpider(ArticleSpider为项目名称)
以上这篇mac安装scrapy并创建项目的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。