如何检查加载的url?

2024-03-29 09:56:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个类似的代码:

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_()

我觉得我做得完全不对。理想情况下,我想加载这两个网址,并将其连接到适当的插槽,但现在我只想出这种解决方案。你知道吗


Tags: to代码inbrselfappurlif
1条回答
网友
1楼 · 发布于 2024-03-29 09:56:39

获取当前url时使用:

self.url().toString()

然后您可以检查:

    if 'example' in self.url().toString() \
    or self.url().toString().endswith('example') \ 
    or 'example' in self.url().toString().split("/"):
        pass

相关问题 更多 >