Search code examples
pythonqtpyqtpyqt5webengine

PyQt5 + QtWebEngine get html element?


everyone! I want port my project from Qt WebKit to Qt WebEngine! Currently I want to get the html elemnt.

I use PyQt5 + QT 5.8.

My get elment func:

def get_elment(self,selector,func):
    js = '''
        function r() 
        {
            var button = document.querySelector("%s");
            return button;
        }
        r();
    '''%selector
    self.wp.runJavaScript(js,func)

I use it :

def print_element(e):
    print "e:%s"%e
browser.get_elment('#u1 > a:nth-child(1)',print_element)

I hope e should be a html element, but it is a dict. the result:

the result

I search on the web, but could not find the solution. Can anyone help me ? Thanks very much!


Solution

  • Thanks for @ekhumoro.

    There is no equivalent to QWebElement in Qt WebEngine. All DOM manipulations must be done in Javascript.