#!/usr/bin/python# -*- coding: latin-1 -*-import sysimport base64from PyQt4.QtGui import *from PyQt4.QtCore import *from PyQt4.QtWebKit import *from PyQt4 import QtNetworkclass Render(QWebPage): def __init__(self, url): self.app = QApplication(sys.argv) username = 'username' password = 'password' base64string = base64.enprestring('%s:%s' % (username, password))[:-1] authheader = "Basic %s" % base64string headerKey = QByteArray("Authorization") headerValue = QByteArray(authheader) url = QUrl(url) req = QtNetwork.QNetworkRequest() req.setRawHeader(headerKey, headerValue) req.setUrl(url) QWebPage.__init__(self) self.loadFinished.connect(self._loadFinished) self.mainframe().load(req) self.app.exec_() def _loadFinished(self, result): self.frame = self.mainframe() self.app.quit()def main(): url = 'http://www.google.com' r = Render(url) html = r.frame.toHtml()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)