本文共 606 字,大约阅读时间需要 2 分钟。
源码没有看,应该是用python封装了pyqtwebkit。
需要安装pyqt4(sudo apt-get install python-qt4)
简单示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | from ghost import Ghost import time def main(): ghost = Ghost() start = time.time() page, resources = ghost. open ( "http://www.baidu.com/" ) end = time.time() #保存了所有的资源,包括js for res in resources: print res.url, res.http_status print ghost.content #输出内容 ghost.capture_to( '/home/chenjianshu/tmp/header.png' ) #截图 print end - start main() |
其它功能官网上都有写,功能不多,但简单够用。性能一般,毕竟是完整浏览器,不能要求太多。page返回是None比较奇怪,得有空看下源码。
本文转自 dogegg250 51CTO博客,原文链接:http://blog.51cto.com/jianshusoft/1315870,如需转载请自行联系原作者