简体   繁体   中英

Problems with finding QWebElements by tag in PySide

I am using QGraphicsWebView and trying to iterate over QWebElements. At first tried :

frame = self.page().mainFrame()
doc = frame.documentElement()

h = frame.findFirstElement("head")
b = frame.findFirstElement("body")

elements = h.findAll("link")
for d in elements :
    print d.tagName()

So you see what I thought but, but later on find that there's elements in QWebElementCollection, not in list. Please help me with iterating over DOM tree.

a QWebElement 's findAll method returns a QWebElementCollection , which can be converted to a QList instance with it's toList() method. To iterate over a list of matched elements, you could use:

body_element = frame.findFirstElement("body")

for el in body_element.findAll("div").toList():
    print el.tagName()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM