#!/usr/bin/env python
import re
import sys
import PyQt4
from PyQt4 import QtCore, QtGui ,QtWebKit
from PyQt4 import uic
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
from PyQt4.QtNetwork import *
from PyQt4.QtCore import SIGNAL, QUrl, QString, Qt, QEvent
from PyQt4.QtCore import QSize, QDateTime, QPoint
from PyQt4.QtGui import QApplication, QImage, QPainter
from PyQt4.QtGui import QCursor, QMouseEvent, QKeyEvent
from PyQt4.QtNetwork import QNetworkCookie, QNetworkAccessManager
from PyQt4.QtNetwork import QNetworkCookieJar, QNetworkRequest, QNetworkProxy
from PyQt4.QtWebKit import QWebPage, QWebView
class WebPage(QWebPage):
def __init__(self, user_agent):
QWebPage.__init__(self)
# set user agent
self.user_agent = user_agent
def userAgentForUrl(self, url):
#~ return self.user_agent
return QString(QByteArray(self.user_agent))
def javaScriptAlert(self, frame, message):
"""Override default javascript alert popup
"""
print 'Alert:', message
class IEWinApp:
def __init__(self,url):
self.url=url
self.REGEXPS = \
{
'cookie':re.compile(r'(?P\S*?)\s*=\s*(?P\S*?);', re.I | re.DOTALL)
}
cookie_input = "acookie=a; bcookie=b; ccookie=c;"
#~ self.current = "http://www.useragentstring.com/"
cookiebase = QNetworkCookie("","")
self.cookies = cookiebase.parseCookies("")
for cookiename,cookievalue in self.REGEXPS['cookie'].findall(cookie_input):
cookie_tmp = QNetworkCookie(QByteArray(cookiename),QByteArray(cookievalue))
self.cookies.append(cookie_tmp)
self.cookiejar = QNetworkCookieJar()
#~ self.cookiejar.setCookiesFromUrl(self.cookies, QUrl(self.current))
self.network_manager = QNetworkAccessManager()
self.network_manager.setCookieJar(self.cookiejar)
self.network_manager.sslErrors.connect(on_ssl_errors)
#~ self.window = WebBrowser()
self.page = IEWinPage()
#~ agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)1"
agent="default"
self.page.setUserAgent(agent)
self.page.setNetworkAccessManager(self.network_manager)
self.frame = self.page.mainFrame()
#~ self.window.webView.setPage(self.page)
self.webView=QWebView()
self.webView.setPage(self.page)
self.webView.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled,True)
#~ self.frame.load(QUrl(self.current))
self.webView.load(QUrl(self.url))
#~ self.window.show()
self.webView.show()
def on_ssl_errors(reply, errors):
url = unicode(reply.url().toString())
reply.ignoreSslErrors()
print "SSL certificate error ignored: %s" % url
class IEWinPage(QWebPage):
def __init__(self):
QWebPage.__init__(self)
self.useragent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
def setUserAgent(self, agent):
if agent=="default":
self.useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28"
else:
self.useragent = agent
def userAgentForUrl(self, url):
return QString(QByteArray(self.useragent))
if __name__ == "__main__":
app = QApplication(sys.argv)
url= "http://facebook.com"
#~ url= "http://google.com"
#~ url= "http://www.youtube.com/watch?v=v8HoVdenZFM"
win = IEWinApp(url)
sys.exit( app.exec_() )
i can watch youtube with this script
.heehehehe.i like python