the code I tried is as follows:
from PyQt5 import QtCore, QtGui
from PyQt5.QtWebEngineWidgets import QWebEngineView,QWebEnginePage
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
ui = QWebEngineView()
class global_var:
pagename=""
def load_baidu():
global_var.pagename="baidu"
print("load baidu")
ui.load(QUrl("http://www.baidu.com"))
def load_oschina():
global_var.pagename="oschina"
print("load oschina")
ui.load(QUrl("https://www.oschina.net/"))
def onStart():
print ("Started..." )
def onDone():
print ("load ok---",global_var.pagename)
ui.loadStarted.connect(onStart)
ui.loadFinished.connect(onDone)
load_baidu()
-sharptime.sleep(2)
load_oschina()
ui.showMaximized()
sys.exit(app.exec_())
is to trigger loadFinished (), after a page is loaded and run different functions. The question is how can I wait until the last web page is loaded, trigger the corresponding function, and then load the subsequent web page.
tried many times, but failed to achieve the desired results in the end. It was not long before I came into contact with programming (python) and had no choice but to ask for help.
update: if you think about it, you can add something after load_baidu () that prevents the process from running down (not very well described), and then wait for loadFinished () to be triggered and then unblocked. I wonder if there is a corresponding way?
Update: found a not-so-good solution, not elegant, but finally able to run and achieve my needs.
A better way is waiting for the boss"s help
import sys,time
from PyQt5 import QtCore, QtGui
from PyQt5.QtWebEngineWidgets import QWebEngineView,QWebEnginePage
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
run_time=0
app = QApplication(sys.argv)
ui = QWebEngineView()
class global_var:
pagename=""
loadover="no"
def load_baidu():
global_var.pagename="baidu"
print("load baidu")
ui.load(QUrl("http://www.baidu.com"))
-sharp while global_var.loadover=="no":
-sharp pass
-sharp global_var.loadover="no"
def load_oschina():
global_var.pagename="oschina"
print("load oschina")
ui.load(QUrl("https://www.oschina.net/"))
-sharp while global_var.loadover=="no":
-sharp pass
-sharp global_var.loadover="no"
def onStart():
print ("Started..." )
def onDone():
global_var.loadover="yes"
print ("load ok---",global_var.pagename)
global run_time
if run_time==0:
load_oschina()
run_time=1
elif run_time==1:
print("done")
ui.loadStarted.connect(onStart)
ui.loadFinished.connect(onDone)
ui.showMaximized()
load_baidu()
-sharptime.sleep(2)
-sharpload_oschina()
sys.exit(app.exec_())