Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何检查加载的url?_Python_Qt_Pyqt_Pyqt4_Pyside - Fatal编程技术网

Python 如何检查加载的url?

Python 如何检查加载的url?,python,qt,pyqt,pyqt4,pyside,Python,Qt,Pyqt,Pyqt4,Pyside,我有一个类似于以下内容的代码: 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 '

我有一个类似于以下内容的代码:

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

我有一种感觉,我做得完全错了。理想情况下,我希望加载这两个url并将其连接到适当的插槽,但目前我仅提出这种解决方案。

您可以通过以下方式获得当前url:

self.url().toString()
然后,您可以通过以下方式进行检查:

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

您可以通过以下方式获取当前url:

self.url().toString()
然后,您可以通过以下方式进行检查:

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

你说得对,这很有效。但不幸的是,它没有给出正确的结果,因此它没有检查urlis
http://example“
您正在加载的url?如果self.url().toString().endswith('example/')正确,则可以使用
检查它是否重定向到。但不幸的是,它没有给出正确的结果,因此它没有检查urlis
http://example“
您正在加载的url?因为它重定向到,所以您可以使用
检查self.url().toString().endswith('example/')