python - QWebEngine.loadFinished.connect() 是做什么的?

标签 python python-3.x pyqt5

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *


app = QApplication([])

view = QWebEngineView()
view.show()

url = 'http://gama-gama.ru/search/?searchField=titan'
view.load(QUrl(url))

#what does this function call do?
view.loadFinished.connect(lambda x: view.grab().save('img.jpg'))

app.exec()

loadFinished 函数的作用是什么?我知道它是一个“信号”,但调用 view.loadFinished() 会说 TypeError: native Qt signal is not callable.

我可以使用 view.loadFinished.connect(is_finished_function) 来防止页面在出现特定文本之前认为已加载吗?

最佳答案

Loadfinished 是一个 QSignal

QSignal 是一个实现了以下方法的类:connect()disconnect()emit(),这只能是继承自QObject的类的属性。

void QWebView::loadFinished(bool ok)

This signal is emitted when a load of the page is finished. ok will indicate whether the load was successful or any error occurred.

就您而言,我认为您正在使用它来让您知道我何时完全加载页面(有或没有错误),此时您调用该函数:

 lambda x: view.grab().save('img.jpg')

关于python - QWebEngine.loadFinished.connect() 是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41901754/

相关文章:

python-3.x - python小数精度

python - 如何将 .py 转换为 .exe(32 位)

python - PyQt5加载网页内容时返回None值

python - 如何编译使用 python 3.8 的 PyQt5 程序

python - 无法在 Windows 中安装 Scipy?

python - 在 python 中指定日期时间所在的时区

python - Tkinter、Python 中框架的垂直滚动条

python - 通过函数传递变量/列表

python请求引发了SSLError,如何解决?

python - python中大型数据集的后向消除