python 安装ssh和Scrapy
在Python中没有专用的SSH模块,这需要手动的安装模块才行。Python中使用SSH需要用到OpenSSH,而OpenSSH依赖于paramiko模块,paramiko模块又依赖于pycrypto模块,因此要在Python中使用SSH,需要安装模块的顺序是pycrypto-〉paramiko。
安装OpenSSH
OpenSSH下载网址:http://sourceforge.net/projects/sshwindows/,下载安装即可。
安装Pycrypto模块
Pycrypto模块下载地址:http://pypi.python.org/pypi/pycrypto/,下载安装时缺少vcvarsall.bat,提示需要VisualStudio,网上解决办法大部分是安装MingW32。
在网上找到已经编译好的Windows中使用的Pycrypto版本,下载网址为:
http://www.voidspace.org.uk/python/modules.shtml#pycrypto
下载Python版本和操作系统对应的版本,直接安装即可。
注:如果是Win32bit + Python 2.7,则下载pycrypto-2.6.win32-py2.7.exe。
使用SSH登陆到远程主机执行命令。
import paramiko
def ssh_cmd(ip,port, cmd, user, passwd):
result = ""
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, port, user, passwd,timeout=3)
stdin, stdout, stderr =ssh.exec_command(cmd)
result = stdout.read()
ssh.close()
except:
print("ssh_cmd err.")
return result
http://stackoverflow.com/questions/1939107/python-libraries-for-ssh-handling
安装Scrapy:
pip install scrapy
报错:
only found improper OpenSSL directories:['E:\\cygwin','E:\\Program Files\\Git'] 答案:Apparently pyopenssl installation expects the binaries and libs to be laid out exactly as installed byOpenSSL windows binaries. Installing it from there (and not using cygwin's openssl for example), and adding the bin directory to the path solved this issue.(来自http://stackoverflow.com/questions/9151268/installing-scrapy-pyopenssl-in-windows-virtualenv)
看来要安装openssh,python中有专门的库pyopenssh
发现用上面的指令安装不是很好。
用下面的安装:
easy_install -U Scrapy (安装0.24版本easy_install -U "Scrapy= =0.24")
会自动下载pyopenssh和twisted库。Scrapy是基于 Twisted 实现的。
http://scrapy.org/
官网上的安装条件:
发现通过pip安装比较好, pip install 'Markdown<2.0' 指定版本= = ,>等。
Pre-requisites
The installation steps assume that you have the following things installed:
Python 2.6 or 2.7
OpenSSL. This comes preinstalled in all operating systems except Windows (see Platform specific installation notes)
pip or easy_install Python package managers
都安装成功后,运行:
scrapy startproject tutorial 报错:
File "E:\ProgramFiles\pythonxy\python27\lib\site-packages\lxml\html\__init__.py", line 42, in <module>
from lxml import etree
ImportError: DLL load failed: 找不到指定的程序。
肯缺少lxml,去下载安装:https://pypi.python.org/pypi/lxml/3.2.1安装后这个错误没有了,又有新的错误:
File "E:\ProgramFiles\pythonxy\python27\lib\site-packages\twisted\web\http.py", line 76, in <module>
from urllib.parse import (
ImportError: No module named parse
我重新安装Scrapy:
可以看到scrapy依赖项:
Twisted
w3lib
lxml
pyOpenssl
zope.interface 没办法,卸载Scrapy:
pip uninstall SCrapy 然后单独下载安装:
twisted http://twistedmatrix.com/trac/ 下载 python2.7的版本
w3lib https://github.com/scrapy/w3lib
lxml:
pyOpenssl:https://pypi.python.org/pypi/pyOpenSSL
zopen.interface
参考:http://www.tuicool.com/articles/NzAF7n
经过以上重装后还是错误:
from urllib.parse import (
ImportError: No module named parse不知道怎么办了?stackoverflow上也有一个人跟我有同样的错误:http://stackoverflow.com/questions/15011205/cant-install-pip-due-to-importerror-no-module-named-parse在windows下安装scrapy的方法详解twiseted 教程http://blog.sina.com.cn/s/blog_704b6af70100py9n.html 安装Scrapy 步骤:http://www.crifan.com/install_scrapy/
http://www.cnblogs.com/CLTANG/archive/2011/07/05/2098531.html
找不到Python.h文件,ubutnu要安装:
apt-get install python-dev
ubuntion通过easy_install -U scrapy报错。
无法打开包括文件:“openssl/aes.h”: No such file or directory。
解决方法:
sudo apt-get install libssl0.9.8
sudo apt-get install libssl-dev
sudo apt-get install libssh-dev
至此,再次运行sudo easy_install pyopenssl 成功安装pyopenssl。(ubuntu python版本:Python 2.7.6).
看了easy_install也不能完全处理依赖关系啊。
参考:http://yueyizx.blog.51cto.com/4006053/1430518
http://www.cnblogs.com/ffan/p/3870324.html
python 安装ssh和Scrapy的更多相关文章
- 芝麻HTTP:Python爬虫进阶之Scrapy框架安装配置
初级的爬虫我们利用urllib和urllib2库以及正则表达式就可以完成了,不过还有更加强大的工具,爬虫框架Scrapy,这安装过程也是煞费苦心哪,在此整理如下. Windows 平台: 我的系统是 ...
- Python、pip和scrapy的安装——Python爬虫学习笔记1
Python作为爬虫语言非常受欢迎,近期项目需要,很是学习了一番Python,在此记录学习过程:首先因为是初学,而且当时要求很快速的出demo,所以首先想到的是框架,一番查找选用了Python界大名鼎 ...
- python安装scrapy
Scrapy基于事件驱动网络框架 Twisted 编写,Twisted是一个异步非阻塞框架. 安装 scrapy 要先安装 Twisted,不然无法安装成功,链接: Python Extension ...
- Python安装scrapy过程中出现“Failed building wheel for xxx”
https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml Python安装scrapy库过程中出现“ Failed building wheel for xxx ...
- 分布式爬虫搭建系列 之一------python安装及以及虚拟环境的配置及scrapy依赖库的安装
python及scrapy框架依赖库的安装步骤: 第一步,python的安装 在Windows上安装Python 首先,根据你的Windows版本(64位还是32位)从Python的官方网站下载Pyt ...
- 网络爬虫(蜘蛛)Scrapy,Python安装!
Scrapy,Python安装.使用! 1.下载安装Python2.7.6.由于Scrapy还不支持3.x版本号. Latest Python 2 Release - Python 2.7.6,安装时 ...
- python爬虫系列:Scrapy安装与使用
这篇博文主要写Scrapy框架的安装与使用 Scrapy框架安装 命令行进入C:\Anaconda2\Scripts目录,运行:conda install Scrapy 创建Scrapy项目 1)进入 ...
- Python爬虫进阶之Scrapy框架安装配置
Python爬虫进阶之Scrapy框架安装配置 初级的爬虫我们利用urllib和urllib2库以及正则表达式就可以完成了,不过还有更加强大的工具,爬虫框架Scrapy,这安装过程也是煞费苦心哪,在此 ...
- python安装Scrapy框架
看到自己写的惨不忍睹的爬虫,觉得还是学一下Scrapy框架,停止一直造轮子的行为 我这里是windows10平台,python2和python3共存,这里就写python2.7安装配置Scrapy框架 ...
随机推荐
- Java中byte转int的方法
byte转化为int有两种情况: 1)要保持数值不变 应用场景:数值计算.等等. 方法:能够直接採用强制类型转换:int i = (int) aByte, 比如:若aByte=0xff(即数值为-1) ...
- java web分享ppt大纲 -- servlet包
概述 servlet相关代码所在包: javax.servlet javax.servlet.http 常用的功能模块 Servlet,filter,listener 常用的相关类: servlet ...
- ASPxGridView后台获取edit、delete、选择框等按钮。
GridViewCommandColumn commandColumn = (GridViewCommandColumn)ASPxGridViewInstance.Columns["#&qu ...
- 线段树讲解(数据结构、C++)
声明 : 仅一张图片转载于http://www.cnblogs.com/shuaiwhu/archive/2012/04/22/2464583.html,自己画太麻烦了...那个博客的讲解也很好 ...
- AWT和Swing
布局分类 一.流式布局 二.边界布局 三.网格布局 四.卡片布局 五.坐标式布局 随意布置控件位置. 六.混合布局
- input file 模拟
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- 运用DIV拖拽实现resize和碰撞检测
运用DIV拖拽实现resize和碰撞检测 Div由拖拽改变大小 演示demo 当我们运用html元素"textarea"写一个文本输入框时,浏览器会自动生成以下样式 用鼠标拖动右下 ...
- ipc$爆破密码
FOR /L %%i IN (1,1,99) DO net use \\192.168.1.1\ipc$ /user:test %%i && echo %%i>1.txt
- Elasticsearch 单模式下API的增删改查操作
<pre name="code" class="html">Elasticsearch 单模式下API的增删改查操作 http://192.168. ...
- [用UpdateLayeredWindow实现任意异形窗口]
前面提到,我们可以用SetWindowRgn或SetLayeredWindowAttributes实现不规则以及半透明的效果 对于SetWindowRgn,它通过一个Rgn来设置区域,这个Rgn一般可 ...
