def initUI(self): # Plugin QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) self.b = QWebView() PGrupo = None PID = None Pregunta = input("Elige [ ID ] o [ GRUPO ] (Respeta mayúsculas) : ") if Pregunta == "GRUPO": clear() PGrupo = input("Escribe el nombre del [ GRUPO ] : ") self.b.load(QUrl("http://xat.com/"+PGrupo)) elif Pregunta == "ID": clear() PID = int(input("Escribe la [ID] : ")) self.b.load(QUrl("http://xat.com/web_gear?id="+PID)) else: print("Asi no idiota") return self.initUI() self.b.setWindowTitle('SearchXat') # Icon #self.b.setWindowIcon(QtGui.QIcon('icon.png')) self.b.show()
def get_site_text(url='https://test.api.unistream.com/help/index.html'): """Функция возвращает содержимое по указанному url.""" import sys from PySide.QtGui import QApplication from PySide.QtCore import QEventLoop from PySide.QtWebKit import QWebSettings, QWebPage, QWebView from PySide.QtNetwork import QNetworkProxyFactory # Чтобы не было проблем запуска компов с прокси: QNetworkProxyFactory.setUseSystemConfiguration(True) QWebSettings.globalSettings().setAttribute( QWebSettings.DeveloperExtrasEnabled, True) class WebPage(QWebPage): def userAgentForUrl(self, url): return 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0' if QApplication.instance() is None: QApplication(sys.argv) view = QWebView() view.setPage(WebPage()) view.load(url) # Ждем пока прогрузится страница loop = QEventLoop() view.loadFinished.connect(loop.quit) loop.exec_() doc = view.page().mainFrame().documentElement() print(len(doc.toOuterXml()), len(doc.toPlainText())) return doc.toPlainText()
def __init__(self, edit): QWebPage.__init__(self) self.current = None self.edit = edit self.active_image = None self.active_link = None self.active_table = None settings = self.settings() family = self.edit.app.settings.value( 'note-font-family', DEFAULT_FONT, ) size = int(self.edit.app.settings.value( 'note-font-size', DEFAULT_FONT_SIZE, )) settings.setFontFamily( QWebSettings.StandardFont, family, ) settings.setFontSize( QWebSettings.DefaultFontSize, size, ) settings.setFontSize( QWebSettings.DefaultFixedFontSize, size, ) QWebSettings.globalSettings().setAttribute( QWebSettings.DeveloperExtrasEnabled, True, ) # This allows JavaScript to call back to Slots, connect to Signals # and access/modify Qt props self.mainFrame().addToJavaScriptWindowObject("qpage", self)
def __init__(self, parent, interval): super(IntervalMap, self).__init__(parent) #assert interval.geodata, "IntervalMap only works with an interval with geodata" self.interval = interval self.setContentsMargins(0, 0, 0, 0) self.setPage(ConsoleLoggerWebPage()) QWebSettings.globalSettings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True) self.page().view().setContentsMargins(0, 0, 0, 0) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.setAcceptDrops(False) self.page().mainFrame().javaScriptWindowObjectCleared.connect(self.updateFrame)
def testPlugin(self): view = QWebView() fac = PluginFactory() view.page().setPluginFactory(fac) QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) view.load(QUrl(os.path.join(os.path.abspath(os.path.dirname(__file__)), "qmlplugin", "index.html"))) view.resize(840, 600) view.show() QTimer.singleShot(500, self.app.quit) self.app.exec_()
def main(): app = QApplication([]) view = QWebView() fac = PluginFactory() view.page().setPluginFactory(fac) QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) view.load(QUrl(sys.argv[1])) view.resize(840, 600) view.show() return app.exec_()
def update_web_settings(settings=None): """ @param settings QWebSettings or None """ from PySide.QtWebKit import QWebSettings ws = settings or QWebSettings.globalSettings() ws.setAttribute(QWebSettings.PluginsEnabled, True) ws.setAttribute(QWebSettings.JavaEnabled, True) ws.setAttribute(QWebSettings.DnsPrefetchEnabled, True) # better performance ws.setAttribute(QWebSettings.AutoLoadImages, False) # do NOT load images #ws.setAttribute(QWebSettings.JavascriptCanOpenWindows, True) #ws.setAttribute(QWebSettings.JavascriptCanAccessClipboard, True) #ws.setAttribute(QWebSettings.DeveloperExtrasEnabled, True) #ws.setAttribute(QWebSettings.OfflineStorageDatabaseEnabled, True) #ws.setAttribute(QWebSettings.OfflineWebApplicationCacheEnabled, True) #ws.setAttribute(QWebSettings.LocalStorageEnabled, True) #ws.setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True) #ws.setAttribute(QWebSettings.ZoomTextOnly, False) #ws.setDefaultTextEncoding("SHIFT-JIS") #ws.setDefaultTextEncoding("EUC-JP") #ws.setLocalStoragePath(G_PATH_CACHES) #QWebSettings.setIconDatabasePath(G_PATH_CACHES) #QWebSettings.setOfflineStoragePath(G_PATH_CACHES) #QWebSettings.setOfflineWebApplicationCachePath(G_PATH_CACHES) # See: http://webkit.org/blog/427/webkit-page-cache-i-the-basics/ ws.setMaximumPagesInCache(10) # do not cache lots of pages
def __init__(self, parent=None, userData=None,inspector = True): QWebView.__init__(self, parent) settings = QWebSettings.globalSettings() settings.setFontFamily(QWebSettings.StandardFont, 'Helvetica') settings.setFontSize(QWebSettings.DefaultFontSize, 12) self.webpage = page = PtWebPage(self) self.setPage(page) self.connect(self, SIGNAL('loadFinished(bool)'), self.onLoadFinished) self.settings().setAttribute( QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) #path = os.getcwd() #self.settings().setUserStyleSheetUrl(QUrl.fromLocalFile(path + "/myCustom.css")) font = QFont("Helvetica") font.setPixelSize(12) self.setFont(font) # or globally: # QWebSettings.globalSettings().setAttribute( # QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) if inspector: self.inspector = QWebInspector() self.inspector.setPage(self.page()) self.inspector.hide() self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.page().linkClicked.connect(self._on_page_link_clicked)
def url_icon(url): """ @param str|QUrl @return QIcon not None """ if not isinstance(url, QUrl) and '://' not in url: url = 'http://' + url return QWebSettings.iconForUrl(url) or icon('logo-browser')
def testPlugin(self): view = QWebView() fac = PluginFactory() view.page().setPluginFactory(fac) QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) view.load( QUrl( os.path.join(os.path.abspath(os.path.dirname(__file__)), 'qmlplugin', 'index.html'))) view.resize(840, 600) view.show() QTimer.singleShot(500, self.app.quit) self.app.exec_()
def update_web_settings(settings=None): """ @param settings QWebSettings or None """ # FIXME: This has no effect! # 9/6/2014: I have to modify bool SecurityOrigin::canRequest(const KURL& url) const in order to disable it. # See: http://qt-project.org/forums/viewthread/31888 # # When combined with QWebSettings.LocalContentCanAccess*, it will by pass same-domain constraints #from PySide.QtWebKit import QWebSecurityOrigin #for scheme in 'http', 'https': # QWebSecurityOrigin.addLocalScheme(scheme) #dprint("local security origin schemes:", QWebSecurityOrigin.localSchemes()) from PySide.QtWebKit import QWebSettings import rc ws = settings or QWebSettings.globalSettings() ws.setAttribute(QWebSettings.PluginsEnabled, True) ws.setAttribute(QWebSettings.JavaEnabled, True) ws.setAttribute(QWebSettings.DnsPrefetchEnabled, True) # better performance ws.setAttribute(QWebSettings.JavascriptCanOpenWindows, True) ws.setAttribute(QWebSettings.JavascriptCanAccessClipboard, True) # Only enable this when debugging if config.APP_DEBUG: ws.setAttribute(QWebSettings.DeveloperExtrasEnabled, True) ws.setAttribute(QWebSettings.OfflineStorageDatabaseEnabled, True) ws.setAttribute(QWebSettings.OfflineWebApplicationCacheEnabled, True) ws.setAttribute(QWebSettings.LocalStorageEnabled, True) ws.setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True) ws.setAttribute(QWebSettings.LocalContentCanAccessFileUrls, True) #ws.setAttribute(QWebSettings.LocalContentCanAccessFileUrls, False) # needed by same-origin-policy ws.setAttribute(QWebSettings.ZoomTextOnly, False) #ws.setDefaultTextEncoding("SHIFT-JIS") cachedir = rc.DIR_CACHE_WEB # Qt will automaticaly create this folder if not exist ws.setLocalStoragePath(cachedir) ws.setIconDatabasePath(cachedir) ws.setOfflineStoragePath(cachedir) ws.setOfflineWebApplicationCachePath(cachedir) # See: http://webkit.org/blog/427/webkit-page-cache-i-the-basics/ #QWebSettings.setMaximumPagesInCache(30) # default is 0 dprint("pass")
def main(): signal.signal(signal.SIGINT, signal.SIG_DFL) args = argument_parser.parse_args() if args.debug: logger = logging.getLogger() logger.setLevel(logging.DEBUG) formatter = logging.Formatter( "%(asctime)s: %(levelname)s: %(message)s", "%Y-%m-%d %H:%M:%S") handler = logging.StreamHandler() handler.setFormatter(formatter) logger.addHandler(handler) app = QApplication(sys.argv) QWebSettings.globalSettings() \ .setAttribute(QWebSettings.PluginsEnabled, not args.noplugin) webthumbnailer = WebThumbnailer(args.window_width, args.window_height) def on_finished(ok): webthumbnailer.save(args.out, args.width, args.height) QApplication.exit(0 if ok else 1) def on_timedout(): webthumbnailer.save(args.out, args.width, args.height) QApplication.exit(0 if webthumbnailer.ok else 1) if args.timeout is None: webthumbnailer.finished.connect(on_finished) else: QTimer.singleShot(int(args.timeout * 1000), on_timedout) if args.url: webthumbnailer.load(args.url) elif args.content: webthumbnailer.set_content(base64.b64decode(args.content)) sys.exit(app.exec_())
def __init__(self, edit): QWebPage.__init__(self) self.current = None self.edit = edit self.active_image = None self.active_link = None self.active_table = None settings = self.settings() family = self.edit.app.settings.value( 'note-font-family', DEFAULT_FONT, ) size = int( self.edit.app.settings.value( 'note-font-size', DEFAULT_FONT_SIZE, )) settings.setFontFamily( QWebSettings.StandardFont, family, ) settings.setFontSize( QWebSettings.DefaultFontSize, size, ) settings.setFontSize( QWebSettings.DefaultFixedFontSize, size, ) QWebSettings.globalSettings().setAttribute( QWebSettings.DeveloperExtrasEnabled, True, ) # This allows JavaScript to call back to Slots, connect to Signals # and access/modify Qt props self.mainFrame().addToJavaScriptWindowObject("qpage", self)
def update_web_settings(settings=None): """ @param settings QWebSettings or None """ from PySide.QtWebKit import QWebSettings, QWebSecurityOrigin import rc # When combined with QWebSettings.LocalContentCanAccess*, it will by pass same-domain constraints dprint("disable same origin principal") for scheme in 'http', 'https': QWebSecurityOrigin.addLocalScheme(scheme) #QWebSecurityOrigin.removeLocalScheme('qrc') #dprint("local security origin schemes:", QWebSecurityOrigin.localSchemes()) ws = settings or QWebSettings.globalSettings() ws.setAttribute(QWebSettings.PluginsEnabled, True) ws.setAttribute(QWebSettings.JavaEnabled, True) ws.setAttribute(QWebSettings.DnsPrefetchEnabled, True) # better performance ws.setAttribute(QWebSettings.JavascriptCanOpenWindows, True) ws.setAttribute(QWebSettings.JavascriptCanAccessClipboard, True) # Always enabled #if config.APP_DEBUG: ws.setAttribute(QWebSettings.DeveloperExtrasEnabled, True) ws.setAttribute(QWebSettings.OfflineStorageDatabaseEnabled, True) ws.setAttribute(QWebSettings.OfflineWebApplicationCacheEnabled, True) ws.setAttribute(QWebSettings.LocalStorageEnabled, True) ws.setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True) ws.setAttribute(QWebSettings.ZoomTextOnly, False) #ws.setDefaultTextEncoding("SHIFT-JIS") cachedir = rc.DIR_CACHE_WEBKIT # Qt will automatically create this folder if not exist ws.setLocalStoragePath(cachedir) ws.setIconDatabasePath(cachedir) ws.setOfflineStoragePath(cachedir) ws.setOfflineWebApplicationCachePath(cachedir) # See: http://webkit.org/blog/427/webkit-page-cache-i-the-basics/ #QWebSettings.setMaximumPagesInCache(100) # default is 0 dprint("pass")
def __init__(self, parent=None): super(Settings, self).__init__(parent) self.setWindowTitle('Settings, Debugger Application') url = QUrl('http://www.bitcoin.org/') settings = QWebSettings.globalSettings() settings.setAttribute(QWebSettings.DeveloperExtrasEnabled, True) # more settings # http://pyside.org/docs/pyside/PySide/QtWebKit/QWebSettings.html#detailed-description self.webView = QWebView() self.webView.setUrl(url) self.mainLayout = QGridLayout() self.mainLayout.addWidget(self.webView) self.setLayout(self.mainLayout)
#!/usr/bin/env python #-*- coding:utf-8 -*- # # Copyright (c) Collab. # See LICENSE.txt for details. import sys from PySide.QtCore import QUrl, QSize from PySide.QtGui import QApplication from PySide.QtWebKit import QWebView, QWebSettings app = QApplication(sys.argv) settings = QWebSettings.globalSettings() settings.setAttribute(QWebSettings.DnsPrefetchEnabled, True) settings.setAttribute(QWebSettings.JavascriptEnabled, True) settings.setAttribute(QWebSettings.PluginsEnabled, True) settings.setAttribute(QWebSettings.AutoLoadImages, True) settings.setAttribute(QWebSettings.PrivateBrowsingEnabled, False) settings.setAttribute(QWebSettings.LinksIncludedInFocusChain, True) settings.setFontSize(QWebSettings.DefaultFontSize, 16) settings.setFontSize(QWebSettings.DefaultFixedFontSize, 16) web = QWebView() web.load(QUrl("http://collab.com")) web.show() sys.exit(app.exec_())
@Slot() def maximizeWindow(self): wv.showMaximized() @Slot(result=bool) def windowIsMaximized(self): return wv.maximized() window = Property(WebStoryWindow, getWindow) network = Property(WebStoryNetwork, getNetwork) inspector = Property(WebStoryInspector, getInspector) wsehost = WebStoryHost() QWebSettings.globalSettings().setAttribute(QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) QWebSettings.globalSettings().setAttribute(QWebSettings.WebAttribute.OfflineStorageDatabaseEnabled, True) QWebSettings.globalSettings().setAttribute(QWebSettings.WebAttribute.OfflineWebApplicationCacheEnabled, True) QWebSettings.globalSettings().setAttribute(QWebSettings.WebAttribute.LocalStorageEnabled, True) QWebSettings.globalSettings().setAttribute(QWebSettings.WebAttribute.LocalContentCanAccessRemoteUrls, False) # Read game file f = open("wse/game.xml") xml = f.read() f.close(); wsehost.set("game.xml", xml) def add_js(): mainFrame.addToJavaScriptWindowObject("HOST", wsehost)
# coding:utf8 __author__ = 'loong' from ui.broom_tag import TagWidget from elib.eqt.browser import SimpleBrowser from PySide.QtWebKit import QWebSettings from PySide import QtCore, QtGui from elib.elog import log QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) def derive_cls(cls): cls_str = '''class Klass(Parent): _pp = Parent''' tpl = r''' def {0}(self, *a, **ka): v = self._pp.{0}(self, *a, **ka) tpl = '\n'.join(['attr : %s', 'args : %s', 'kargs : %s', 'rv : %s']) log.error__(tpl % ('{0}', a, ka, v)) return v ''' for attr in dir(cls): if not attr.startswith('_') and attr != 'invalidate': if type(getattr(cls, 'tr')) == type(getattr(cls, attr)):
__author__ = 'ipetrash' import sys from PySide.QtGui import QApplication from PySide.QtCore import QEventLoop from PySide.QtWebKit import QWebSettings, QWebView from PySide.QtNetwork import QNetworkProxyFactory # Чтобы не было проблем запуска компов с прокси: QNetworkProxyFactory.setUseSystemConfiguration(True) QWebSettings.globalSettings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True) # Телефон или емейл LOGIN = '******' PASSWORD = '******' URL = 'https://vk.com' if __name__ == '__main__': app = QApplication(sys.argv) view = QWebView() view.show() view.load(URL)
def __init__(self, user_agent=default_user_agent, wait_timeout=8, wait_callback=None, log_level=logging.WARNING, display=False, viewport_size=(800, 600), ignore_ssl_errors=True, cache_dir=os.path.join(tempfile.gettempdir(), "ptwebkit.py"), plugins_enabled=False, java_enabled=False, plugin_path=['/usr/lib/mozilla/plugins', ], download_images=True, qt_debug=False, show_scroolbars=True, network_access_manager_class=None): self.http_resources = [] self.user_agent = user_agent self.wait_callback = wait_callback self.wait_timeout = wait_timeout self.display = display if sys.platform.startswith('linux') and not 'DISPLAY' in os.environ\ and not hasattr(PtWebkit, 'xvfb'): try: os.environ['DISPLAY'] = ':99' PtWebkit.xvfb = subprocess.Popen(['Xvfb', ':99']) except OSError: raise Error('Xvfb is required to a ghost run outside ' + 'an X instance') if not PtWebkit._app: PtWebkit._app = QApplication.instance() or QApplication(['ghost']) qInstallMsgHandler(QTMessageProxy(qt_debug)) if plugin_path: for p in plugin_path: PtWebkit._app.addLibraryPath(p) if network_access_manager_class is not None: self.page.setNetworkAccessManager(network_access_manager_class()) self.page = PtWebPage(PtWebkit._app, self) QWebSettings.setMaximumPagesInCache(0) QWebSettings.setObjectCacheCapacities(0, 0, 0) QWebSettings.globalSettings().setAttribute( QWebSettings.LocalStorageEnabled, True) self.page.setForwardUnsupportedContent(True) self.page.settings().setAttribute( QWebSettings.AutoLoadImages, download_images) self.page.settings().setAttribute( QWebSettings.PluginsEnabled, plugins_enabled) self.page.settings().setAttribute(QWebSettings.JavaEnabled, java_enabled) if not show_scroolbars: self.page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff) self.page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff) self.set_viewport_size(*viewport_size) # Page signals self.page.loadFinished.connect(self._page_loaded) self.page.loadStarted.connect(self._page_load_started) self.page.unsupportedContent.connect(self._unsupported_content) self.manager = self.page.networkAccessManager() self.manager.finished.connect(self._request_ended) self.manager.sslErrors.connect(self._on_manager_ssl_errors) # Cache if cache_dir: self.cache = QNetworkDiskCache() self.cache.setCacheDirectory(cache_dir) self.manager.setCache(self.cache) else: self.cache = None # Cookie jar self.cookie_jar = QNetworkCookieJar() self.manager.setCookieJar(self.cookie_jar) self.main_frame = self.page.mainFrame() # User Agent self.page.setUserAgent(self.user_agent) #logger.setLevel(log_level) class GhostQWebView(QtWebKit.QWebView): def sizeHint(self): return QSize(*viewport_size) self.webview = GhostQWebView() if plugins_enabled: self.webview.settings().setAttribute( QtWebKit.QWebSettings.PluginsEnabled, True) if java_enabled: self.webview.settings().setAttribute( QtWebKit.QWebSettings.JavaEnabled, True) self.webview.setPage(self.page) if self.display: self.webview.show()
# coding:utf8 __author__ = 'loong' from ui.broom_tag import TagWidget from elib.eqt.browser import SimpleBrowser from PySide.QtWebKit import QWebSettings from PySide import QtCore, QtGui from elib.elog import log QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) def derive_cls(cls): cls_str = '''class Klass(Parent): _pp = Parent''' tpl = r''' def {0}(self, *a, **ka): v = self._pp.{0}(self, *a, **ka) tpl = '\n'.join(['attr : %s', 'args : %s', 'kargs : %s', 'rv : %s']) log.error__(tpl % ('{0}', a, ka, v)) return v ''' for attr in dir(cls): if not attr.startswith('_') and attr != 'invalidate': if type(getattr(cls, 'tr')) == type(getattr(cls, attr)): cls_str += tpl.format(attr)