一.Scrapy的介紹
Scrapy是用Python開發的一個快速,高層次的屏幕抓取和web抓取框架,用于抓取web站點并從頁面中提取結構化的數據。Scrapy用途廣泛,可以用于數據挖掘、監測和自動化測試。它有個萌出血的外號叫小抓抓。
下面主要介紹下Scrapy的安裝步驟以及遇到的一些坑。
二,安裝步驟
首先安裝蟒蛇包工具點子,它相當于iOS的開發中的的CocoaPods。
1. $ sudo easy_install pip
安裝成功后執行下面命令
2. $ sudo pip安裝Scrapy
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecatedandwill be removedina future version. Thisisdue 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", line215,inmainstatus = self.run(options, args)File"/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line342,inrunprefix=options.prefix_path,File"/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line778,ininstallrequirement.uninstall(auto_confirm=True)File"/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line754,inuninstallpaths_to_remove.remove(auto_confirm)File"/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line115,inremoverenames(path, new_path)File"/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line267,inrenamesshutil.move(old, new)File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line302,inmovecopy2(src, real_dst)File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line131,incopy2copystat(src, dst)File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line103,incopystatos.chflags(dst, st.st_flags)OSError: [Errno1] Operationnotpermitted:'/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安裝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, builtin3 minutes 19 seconds
4. $ sudo pip安裝Scrapy
出現下面提示則代表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 code1in /private/tmp/pip-build-keKznw/lxml/
按照下面三步重新安裝LXML
1.xcode-select --install2.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/include3.sudo pip install lxml
5.成功后再次執行$ sudo pip install Scrapy
Successfully built Twisted PyDispatcher lxml pycparserInstalling collected packages: cssselect, six, w3lib, queuelib, zope.interface, constantly, incremental, Twisted, PyDispatcher, lxml, enum34, ipaddress, idna, pycparser, cffi, cryptography, pyOpenSSL, parsel, ScrapySuccessfully installed PyDispatcher-2.0.5Scrapy-1.3.0Twisted-16.6.0cffi-1.9.1constantly-15.1.0cryptography-1.7.1cssselect-1.0.0enum34-1.1.6idna-2.2incremental-16.10.1ipaddress-1.0.17lxml-3.7.1parsel-1.1.0pyOpenSSL-16.2.0pycparser-2.17queuelib-1.4.2six-1.10.0w3lib-1.16.0zope.interface-4.3.3You are using pip version8.1.2, however version9.0.1is available.You should consider upgrading via the'pip install --upgrade pip'command.
到這里就已經安裝成功了。(因為Scrapy安裝源被墻,所以安裝過程最好使用VPN)