pyspider是一个python的爬虫框架,安装过程遇到不少坑,在这里总结一下。
安装
安装只需要简单用pip安装就可以了
pip install pyspider
测试
使用
pyspider
或
pyspider all
测试是否安装成功。
C:\Users\hp>pyspider all
c:\users\hp\anaconda3\lib\site-packages\pyspider\libs\utils.py:196: FutureWarning: timeout is not supported on your platform.
warnings.warn("timeout is not supported on your platform.", FutureWarning)
Error: Could not create web server listening on port 25555
[I 210302 17:11:42 result_worker:49] result_worker starting...
[I 210302 17:11:42 processor:211] processor starting...
[I 210302 17:11:43 scheduler:647] scheduler starting...
[I 210302 17:11:43 scheduler:586] in 5m: new:0,success:0,retry:0,failed:0
[I 210302 17:11:43 tornado_fetcher:638] fetcher starting...
[I 210302 17:11:43 scheduler:782] scheduler.xmlrpc listening on 127.0.0.1:23333
[I 210302 17:11:43 app:76] webui running on 0.0.0.0:5000
[I 210302 17:13:43 scheduler:586] in 5m: new:0,success:0,retry:0,failed:0
出现webui running on 0.0.0.0:5000就成功了。
使用
在浏览器内输入
localhost:5000
成功显示后,点击create键创建新项目
问题
坑1:ininvalid syntax报错
File “C:\Users\hp\Anaconda3\Lib\site-packages\pyspider\run.py”, line 231
async=True, get_object=False, no_input=False):
SyntaxError: invalid syntax
原因是:导致这种情况的原因是在更新的python3 中,已经将async 设置为关键字,而pyspider 版本更新缓慢并没有在此处修改,所以导致pyspider 不能正常启动。
处理异常有两种方法:1、降低python 版本,降低至3.5即可,但这种方法过于麻烦。2、修改出现异常的关键字。
这里我们采用第二种方法来解决问题。
主要有两个文件:C:\Users\hp\Anaconda3\Lib\site-packages\pyspider\run.py 和 C:\Users\hp\Anaconda3\Lib\Lib\site-packages\pyspider\fetcher\tornado_fetcher.py
在替换是要注意:只替换名为async 的变量或参数名。不要图省事选择“全部替换”
替换保存后再次运行“pyspider all”
这时spider只启动到“scheduler xmlrpc listening on 127.0.0.1:23333”就停止了
继续替换PYTHON_HOME\Lib\site-packages\pyspider\webui\app.py中的async
坑2:wsgidav版本问题
ValueError: Invalid configuration:
-Deprecated option ‘domaincontroller’: use ‘http_authenticator.domain_controller’ instead.
或卡在
scheduler.xmlrpc listening on 127.0.0.1:23333
即
C:\Users\hp>pyspider all
c:\users\hp\anaconda3\lib\site-packages\pyspider\libs\utils.py:196: FutureWarning: timeout is not supported on your platform.
warnings.warn("timeout is not supported on your platform.", FutureWarning)
Error: Could not create web server listening on port 25555
[I 210302 17:11:42 result_worker:49] result_worker starting...
[I 210302 17:11:42 processor:211] processor starting...
[I 210302 17:11:43 scheduler:647] scheduler starting...
[I 210302 17:11:43 scheduler:586] in 5m: new:0,success:0,retry:0,failed:0
[I 210302 17:11:43 tornado_fetcher:638] fetcher starting...
[I 210302 17:11:43 scheduler:782] scheduler.xmlrpc listening on 127.0.0.1:23333
[I 210302 17:13:43 scheduler:586] in 5m: new:0,success:0,retry:0,failed:0
[I 210302 17:13:43 scheduler:586] in 5m: new:0,success:0,retry:0,failed:0
[I 210302 17:13:43 scheduler:586] in 5m: new:0,success:0,retry:0,failed:0
解决方法1:
打开PYTHON_HOME\Lib\site-packages\pyspider\webui\webdav.py文件,修改第209行
目标位置 : 'domaincontroller': NeedAuthController(app),
更改为 : http_authenticator':{
'HTTPAuthenticator':NeedAuthController(app),
},
保存文件后再次运行
解决方法2:降低版本
因为3.0的版本不兼容,所以替换为2.4.1[4]
pip uninstall wsgidav
pip install wsgidav==2.4.1
坑3:卡在result_worker starting…
如果一直卡在result_worker starting…,如下图所示。
第一个终端
可以新打开一个终端(这个终端暂时不关),再依次输入pyspider,输入完成后再关闭第一个终端。
第二个终端
运行后:
坑4:安装Phantomjs
在官网下载解压后,并将pathtomjs.exe拖进python.exe的同级目录下即可。
网址:http://phantomjs.org/download.html
1. 解压缩找到exe文件>>复制exe文件并复制到python.exe文件所在的位置
a. 找到python.exe:
b. 复制粘贴:
坑5:
C:\Users\hp>pyspider all
c:\users\hp\anaconda3\lib\site-packages\pyspider\libs\utils.py:196: FutureWarning: timeout is not supported on your platform.
warnings.warn("timeout is not supported on your platform.", FutureWarning)
Error: Could not create web server listening on port 25555
找到phantomjs 进程,phantomjs进程未结束,端口被占用,将占用端口杀掉就行了。
功能 | 命令 |
查找所有运行的端口 | netstat -ano |
查看被占用端口对应的 PID | netstat -a |
查看指定 PID 的进程 | tasklist|findstr "9088" |
结束进程 | taskkill /T /F /PID 9088 |
不行的话关机重启。
参考资料:
https://blog.csdn.net/weixin_39190382/article/details/104923254
https://blog.csdn.net/qq_33472765/article/details/80697263
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)