Scrapy使用问题整理(转载)

转载自: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:userszjn3645appdatalocal empxmlXPathInit7hkp2z.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:
 
解决方法:按照官方文档的说明安装
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,
}
原文地址:https://www.cnblogs.com/Devopser/p/6393699.html