Python 爬蟲之Scrapy的安裝

一.Scrapy的介紹

Scrapy是用Python開發(fā)的一個快速,高層次的屏幕抓取和web抓取框架匈庭,
用于抓取web站點并從頁面中提取結(jié)構(gòu)化的數(shù)據(jù)。
Scrapy用途廣泛甜攀,可以用于數(shù)據(jù)挖掘较解、監(jiān)測和自動化測試。
它有個萌出血的外號叫小抓抓赴邻。

下面主要介紹下Scrapy的安裝步驟以及遇到的一些坑。

二.安裝步驟

首先安裝python包工具pip啡捶,它相當(dāng)于iOS開發(fā)中的CocoaPods姥敛。

1. $ sudo easy_install pip

安裝成功后執(zhí)行下面命令

2. $ sudo pip install Scrapy
    DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
    os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-QfQY7O-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

安裝提示Mac自帶的python 2.7版本有誤,所以我們需要重新安裝python

3. $ brew install python

(如果此前沒有安裝過brew瞎暑, 請先安裝彤敛,命令行如下)

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

python 安裝成功后提示:

==> **Summary**
??  /usr/local/Cellar/python/2.7.13: 6,337 files, 86.7M, built in 3 minutes 19 seconds
4. $ sudo pip install Scrapy

出現(xiàn)下面提示則代表lxml 安裝出錯,

Command "/usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-keKznw/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-FEkrEy-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-keKznw/lxml/

按照下面三步重新安裝lxml

1.xcode-select --install  
2.C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2//libxml:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include  
3.sudo pip install lxml 
5. 成功后再次執(zhí)行 $ sudo pip install Scrapy
Successfully built Twisted PyDispatcher lxml pycparser
Installing collected packages: cssselect, six, w3lib, queuelib, zope.interface, constantly, incremental, Twisted, PyDispatcher, lxml, enum34, ipaddress, idna, pycparser, cffi, cryptography, pyOpenSSL, parsel, Scrapy
Successfully installed PyDispatcher-2.0.5 Scrapy-1.3.0 Twisted-16.6.0 cffi-1.9.1 constantly-15.1.0 cryptography-1.7.1 cssselect-1.0.0 enum34-1.1.6 idna-2.2 incremental-16.10.1 ipaddress-1.0.17 lxml-3.7.1 parsel-1.1.0 pyOpenSSL-16.2.0 pycparser-2.17 queuelib-1.4.2 six-1.10.0 w3lib-1.16.0 zope.interface-4.3.3
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

到這里就已經(jīng)安裝成功了了赌。(因為Scrapy安裝源被墻墨榄,所以安裝過程最好使用VPN)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市勿她,隨后出現(xiàn)的幾起案子袄秩,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,122評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件之剧,死亡現(xiàn)場離奇詭異郭卫,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)背稼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,070評論 3 395
  • 文/潘曉璐 我一進(jìn)店門贰军,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人蟹肘,你說我怎么就攤上這事词疼。” “怎么了帘腹?”我有些...
    開封第一講書人閱讀 164,491評論 0 354
  • 文/不壞的土叔 我叫張陵贰盗,是天一觀的道長。 經(jīng)常有香客問我竹椒,道長童太,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,636評論 1 293
  • 正文 為了忘掉前任胸完,我火速辦了婚禮书释,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘赊窥。我一直安慰自己爆惧,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,676評論 6 392
  • 文/花漫 我一把揭開白布锨能。 她就那樣靜靜地躺著扯再,像睡著了一般。 火紅的嫁衣襯著肌膚如雪址遇。 梳的紋絲不亂的頭發(fā)上熄阻,一...
    開封第一講書人閱讀 51,541評論 1 305
  • 那天,我揣著相機(jī)與錄音倔约,去河邊找鬼秃殉。 笑死,一個胖子當(dāng)著我的面吹牛浸剩,可吹牛的內(nèi)容都是我干的钾军。 我是一名探鬼主播,決...
    沈念sama閱讀 40,292評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼绢要,長吁一口氣:“原來是場噩夢啊……” “哼吏恭!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起重罪,我...
    開封第一講書人閱讀 39,211評論 0 276
  • 序言:老撾萬榮一對情侶失蹤樱哼,失蹤者是張志新(化名)和其女友劉穎哀九,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體唇礁,經(jīng)...
    沈念sama閱讀 45,655評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡勾栗,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,846評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了盏筐。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片围俘。...
    茶點故事閱讀 39,965評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖琢融,靈堂內(nèi)的尸體忽然破棺而出界牡,到底是詐尸還是另有隱情,我是刑警寧澤漾抬,帶...
    沈念sama閱讀 35,684評論 5 347
  • 正文 年R本政府宣布宿亡,位于F島的核電站,受9級特大地震影響纳令,放射性物質(zhì)發(fā)生泄漏挽荠。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,295評論 3 329
  • 文/蒙蒙 一平绩、第九天 我趴在偏房一處隱蔽的房頂上張望圈匆。 院中可真熱鬧,春花似錦捏雌、人聲如沸跃赚。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,894評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽纬傲。三九已至,卻和暖如春肤频,著一層夾襖步出監(jiān)牢的瞬間叹括,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,012評論 1 269
  • 我被黑心中介騙來泰國打工宵荒, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留领猾,地道東北人。 一個月前我還...
    沈念sama閱讀 48,126評論 3 370
  • 正文 我出身青樓骇扇,卻偏偏與公主長得像,于是被迫代替她去往敵國和親面粮。 傳聞我的和親對象是個殘疾皇子少孝,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,914評論 2 355

推薦閱讀更多精彩內(nèi)容

  • linux和windows下安裝python拓展包-pycharm、numpy熬苍、scipy稍走、matplotlib袁翁、...
    hzyido閱讀 81,253評論 2 10
  • 本文分享的大體框架包含以下三部分 (1)首先介紹html網(wǎng)頁,用來解析html網(wǎng)頁的工具xpath(2)介紹pyt...
    不忘初心c閱讀 2,555評論 0 14
  • 最近想使用scrapy來開發(fā)網(wǎng)頁爬蟲婿脸,本來開始是打算在windows上開發(fā)的粱胜,但是在嘗試之后,發(fā)現(xiàn)在wind...
    ppc閱讀 1,820評論 1 3
  • 上大學(xué)的時候狐树,手機(jī)還不是每個人的標(biāo)配焙压,與家人聯(lián)系的方式一般就是宿舍電話,和家書抑钟。執(zhí)意要離家很遠(yuǎn)求學(xué)的我涯曲,第一次寫家...
    宵汀閱讀 1,030評論 8 15
  • 身體里的無數(shù)把鎖, 交錯盤旋在塔, 牢牢鎖住了通往各個肢體的通道幻件, 也無情地鎖掉了通向他人之心的小徑。
    ENC閱讀 413評論 2 5