轉載自:http://blog.csdn.net/heu07111121/article/details/50832999
最近嘗試使用Scrapy進行數據抓取,并嘗試在windows7 64位系統上安裝scrapy,下面總結記錄遇到兩個問題和解決方法:
scrapy官網的地址為:http://scrapy.org/
1、首先按照官網的說明,直接pip安裝scrapy,報以下錯誤,提示缺少VC++9.0,報錯信息有給出具體的說明和解決方法。
>>pip?install?scrapy
error:?Microsoft?Visual?C++?9.0?is?required?(Unable?to?find?vcvarsall.bat).?Get?it?from?http://aka.ms/vcpython27
解決方法:直接點擊下載VCForPython27.msi,也直接訪問下面的連接https://www.microsoft.com/en-us/download/details.aspx?id=44266
2、下載并安裝VCForPython27.msi,然后再運行pip install scrapy,再次報錯,提示找不到libxml2庫。
>>pip?install?scrapy
c:\users\zjn3645\appdata\local\temp\xmlXPathInit7hkp2z.c(1)?:?fatal?error?C1083:?Cannot?open?include?file:?'libxml/xpath.h':?No?such?file?or?directory
*********************************************************************************
Could?not?find?function?xmlCheckVersion?in?library?libxml2.?Is?libxml2?installed?
*********************************************************************************
error:?command?'C:\\Users\\zjn3645\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual?C++?for?Python\\9.0\\VC\\Bin\\cl.exe'?failed?with?exit?status?2
解決方法:
使用easy_install安裝lxml,然后再次安裝pip install scrapy,成功~
>>easy_install?lxml
?
3、scrapy安裝完成,運行官網首頁的樣例報錯,原因是缺少pywin32
>>scrapy?runspider?myspider.py
exceptions.ImportError:?No?module?named?win32api
2016-03-09?10:17:49?[twisted]?CRITICAL:
解決方法:按照官方文檔的說明安裝
Install?pywin32?from?https://sourceforge.net/projects/pywin32/files/pywin32/
這里有詳細的說明http://doc.scrapy.org/en/latest/intro/install.html#intro-install-platform-notes
pywin32有32位和64位版本,
對于64位的windows 7,如果python環境變量已經正確安裝,pywin32安裝的時候仍然報找不到python的錯誤,嘗試pywin32的32位版本。
總結:在安裝和使用新的工具之前一定要先看看官方文檔的說明,搞清楚安裝和使用的前提條件!
4、關閉代理
默認使用代理,有些網頁使用本地代理無法訪問!
2016-03-09?15:18:21?[scrapy]?DEBUG:?Telnet?console?listening?on?127.0.0.1:6023
2016-03-09?15:18:21?[scrapy]?DEBUG:?Crawled?(403)?<GET?http://xxx.com.cn/xxx.html>
(referer:?None)
2016-03-09?15:18:21?[scrapy]?DEBUG:?Ignoring?response?<403?http://xxx.com.cn/xxx.html>:?HTTP?status?code?is?not?handled?or?not?allowed
關閉代理
修改settings.py如下
DOWNLOADER_MIDDLEWARES?=?{
????'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware':?None,
}