使用PyQt4的QtWebKit对整个网页截图,pyqt4qtwebkit截图,#-*- coding:
文章由Byrx.net分享于2019-03-23 08:03:41
使用PyQt4的QtWebKit对整个网页截图,pyqt4qtwebkit截图,#-*- coding:
#-*- coding:utf-8 -*-import sysimport os.pathfrom PyQt4 import QtGui,QtCore,QtWebKitclass PageShotter(QtGui.QWidget): def __init__(self,url,parent=None): QtGui.QWidget.__init__(self,parent) self.url = url def shot(self): webView = QtWebKit.QWebView(self) webView.load(QtCore.QUrl(self.url)) self.webPage = webView.page() self.connect(webView,QtCore.SIGNAL("loadFinished(bool)"),self.savePage) def savePage(self,finished): #print finished if finished: print u"开始截图!" size = self.webPage.mainFrame().contentsSize() print u"页面宽:%d,页面高:%d" % (size.width(),size.height()) self.webPage.setViewportSize(QtCore.QSize(size.width()+16,size.height())) img = QtGui.QImage(size, QtGui.QImage.Format_ARGB32) painter = QtGui.QPainter(img) self.webPage.mainFrame().render(painter) painter.end() fileName= "shot.png"; if img.save(fileName): filePath = os.path.join(os.path.dirname(__file__), fileName) print u"截图完毕:%s" % filePath else: print u"截图失败"; else: print u"网页加载失败!" self.close()if __name__=="__main__": app = QtGui.QApplication(sys.argv) shotter = PageShotter("http://byrx.net shotter.shot() sys.exit(app.exec_())#该片段来自于http://byrx.net
相关内容
- Python备份脚本——版本一(Windows),python脚本,参照pytho
- itertools.combinations代码分析,,def combinat
- python查找目录下指定扩展名的文件,python扩展名,impor
- python连接mongodb的基本代码,python连接mongodb,from pymongo
- python对数组进行反转的代码,python数组反转,arr = [1,2,
- python通过函数属性实现全局变量,python全局变量,def a
- python超简代码解决约瑟夫环问题,python约瑟夫,a = [ x
- python赋值方法(类似GO中的赋值方法),pythongo,前几天看
- 定义源码编码 (Source Encoding),sourceencoding,# -*- coding
- 通过python post提交数据的代码演示,pythonpost,# -*- codin
评论关闭