我有一个与此类似的代码:
class A(QWebView):
def __init__(self):
# some code here
# in here I want to check what url is loaded and based on that assign appropriate SLOT
# I was wondering how to do something like that:
# if 'examle.html' in self.url():
# self.loadFinished.connect(self.example)
# else:
# self.loadFinished.connect(self.anotherSLOT)
if __name__ == '__main__':
app = QApplication(sys.argv)
br = A()
br.load(QUrl('http://example')
br.show()
app.exec_()
我有一种感觉,我完全错了。理想情况下,我想加载两个网址并将其连接到适当的插槽,但是现在我只想出这种解决方案。
答案 0 :(得分:1)
您将获得当前网址:
self.url().toString()
然后您可以查看:
if 'example' in self.url().toString() \
or self.url().toString().endswith('example') \
or 'example' in self.url().toString().split("/"):
pass