无法在浏览器中打开新窗口。
我能够浏览gmail登录页面。在页面结尾,有一个隐私或条款标签,在普通浏览器中单击该标签会在新窗口或标签中打开。如何使用PyQt5在代码中打开它。
import sys
import os
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets, QtPrintSupport
url = ""
url = "https://www.gmail.com"
app=QtWidgets.QApplication(sys.argv)
icon_file = os.path.dirname(os.path.realpath(__file__)) + "/ma-icon-64.png"
app.setWindowIcon(QIcon(icon_file))
app.setApplicationName("My browser")
def page_load_progress(progress):
print("loaded --> " + str(progress))
def _downloadRequested(item): # QWebEngineDownloadItem
print('downloading to', item.path())
item.accept()
# printToPdf(item)
def on_url_changed(url):
print("URL CHANGED ......")
print(url)
def call_2():
print("test call 2")
return
if __name__ == "__main__":
if len(url) > 3:
url_load = QtCore.QUrl(url)
elif len(sys.argv) > 1:
url = sys.argv[1]
url_load = QtCore.QUrl(url)
else:
print("No URL found in argument!")
default_html_page = os.path.dirname(os.path.realpath(__file__))+'/default.html'
url_load = QtCore.QUrl().fromLocalFile(default_html_page)
print("= = = = =")
print(url_load)
w = QtWebEngineWidgets
w = w.QWebEngineView()
w.page().fullScreenRequested.connect(QWebEngineFullScreenRequest.accept)
w.page().profile().downloadRequested.connect(_downloadRequested)
w.load(url_load)
w.showMaximized()
app.exec_()