先寫一些前言吧,自己感覺python已經有一定的基礎了,但是在安裝這個過程居然用了一下午,感覺有些收貨,特地寫下來與大家分享一下。

  • PySpider是一個強大的網路爬蟲系統,GitHub地址:https://github.com/binux/pyspider;官方文件地址:http://docs.pyspider.org/en/latest
  • PySpider,提供WEBUI系統,支援PhantomJS進行JS的渲染採集,內建pyquery作為選擇器,可拓展程度不高。
  • Scrapy,原生是程式碼和命令操作,對接Portia實現視覺化,使用parse命令除錯,對接Scrapy-Splash元件進行JS渲染採集,對接XPath/CSS選擇器和正則匹配,可對接Middleware、Pipeline、Extension等元件拓展。
  • PySpider,架構分為Scheduler排程器(發起任務排程),Fetcher抓取器(抓取網頁內容),Processer處理器(解析網頁內容)。

話不多說,上安裝過程(PS,本機環境windows10,Python3.9.0):

1、首先需要安裝PhantomJS,這個比較簡單,就直接按照網上流程安裝對應版本就行。

2、安裝PyCurl,這個是安裝PySpider的先決條件,直接pip安裝會報錯,可以下載.whl檔案安裝,網址https://www.lfd.uci.edu/~gohlke/pythonlibs/#pycurl

3、安裝PySpider,直接pip安裝就行。

4、安裝除錯:

(1)、安裝完Pyspider,命令列執行pyspider,會報錯:SyntaxError: invalid syntax:

這個是因為python以及相關依賴版本過高。可以使用Pycharm (亦可直接用文件更改程式碼),點選File-Open開啟python\lib\sit-packages\pyspider,將資料夾pyspider 載入進去,按Ctrl+Shift+F快捷鍵調出全域性搜尋,輸入async,即可在“In Project”下找到所有含有關鍵字的.py 檔案,逐一開啟,按Ctrl+R調出替換欄,將async 替換為shark 即可。就是分別在run.pytornado_fetcher.pywebui>app.py,ctrl+f查詢async替換掉就可以了。(注意大寫的Async不要替換)

(2)、再次執行發現報錯:AttributeError: module 'fractions' has no attribute 'gcd'

這個函式在Python3.5之後就廢棄了,官方建議使用math.gcd()。所以在libs/base_handler檔案中上方加入 import math下面fractions.gcd()改為math.gcd(…)就可以了

(3)、再次執行發現報錯:Deprecated option 'domaincontroller': use 'http_authenticator.domain_controller' instead.

webui檔案裡面的webdav.py檔案開啟,修改第209行即可。把

'domaincontroller': NeedAuthController(app),

修改為:

'http_authenticator':{
'HTTPAuthenticator':NeedAuthController(app),
},

(4)、再次執行發現報錯:cannot import name 'DispatcherMiddleware' from 'werkzeug.wsgi' (d:\python39\lib\site-packages\werkzeug\wsgi.py)

這個是werkzeug的版本太高問題,需要進行修改

python -m pip  uninstall werkzeug # 解除安裝

python -m pip install werkzeug==0.16.1  
#安裝0.16.1版本

(5)、同樣也需要更換wsgidav
版本

pip uninstall wsgidav

pip install wsgidav==2.4.1

(6)、再次執行pyspider,發現卡死在result_worker starting,執行pyspider all卡死在, fetcher starting…

百度,① 有說需要開啟一個命令列埠執行pyspider,卡住後執行第二個並關掉第一個埠;② 有說需要關閉防火牆;③ 有說需要先安裝redis

但是,我都嘗試一遍還是卡在那裡。

(7)最後選擇重新安裝一遍,

① 把之前安裝的包解除安裝,具有有:wsgidavwerkzeugpycurlpyspider(已經安裝的redis沒有解除安裝,防火牆中python許可權開啟沒關)

② 按照上述(1)~(5)步驟安裝,過程中發現Flask與相關包衝突,並最Flask的版本進行了更新。具體描述如下:

a)發現在安裝 werkzeug 時報錯:

ERROR: pip's dependency resolver does not currently take
into account all the packages that are installed. This behaviour is the source
of the following dependency conflicts.

flask 2.0.1 requires Werkzeug>=2.0, but you have werkzeug
0.16.1 which is incompatible.

b)解除安裝flask,繼續安裝
wsgidav 時報錯:

ERROR: pip's dependency resolver does not currently take
into account all the packages that are installed. This behaviour is the source
of the following dependency conflicts.

pyspider 0.3.10 requires Flask>=0.10, which is not
installed.

c)安裝 flask==1.0.2 ,如果安裝0.10版本,發現pyspider的網頁UI部分內容渲染失敗。1.0.2版本剛好合適

d)安裝成功截圖: