PyQt4练习-通过代理打开一个QWebFrame
2015-7-2 15:24
from PyQt4 import QtGui,QtCore
from PyQt4 import QtWebKit
from PyQt4 import QtNetwork
import sys
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle('Demos for MainWindow')
print 'Initialize MainWindow'
class WebMainWindow(QtWebKit.QWebView):
def __init__(self):
super(WebMainWindow, self).__init__()
self.setWindowTitle('Demos for QtWebKit')
print 'Initialize WebMainWindow'
URL = 'http://www.sina.com'
PROXY_HOST = '*****'
PROXY_PORT = 8080
def set_app_proxy():
proxy = QtNetwork.QNetworkProxy()
proxy.setType(QtNetwork.QNetworkProxy.HttpProxy)
proxy.setHostName(PROXY_HOST)
proxy.setPort(PROXY_PORT)
QtNetwork.QNetworkProxy.setApplicationProxy(proxy)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
#mw = MainWindow()
#mw.show()
#set system proxy
set_app_proxy()
mw = WebMainWindow()
mw.load(QtCore.QUrl(URL))
mw.show()
sys.exit(app.exec_())