开发者

python QtWebkit: nextSibing doesn't return null or None

开发者 https://www.devze.com 2023-02-28 02:31 出处:网络
Below is the code snippet which I use to get a list of all children of the given node. But the the nextSibling() never returns null so the while loop executes forever. 开发者_JAVA技巧Please help.

Below is the code snippet which I use to get a list of all children of the given node. But the the nextSibling() never returns null so the while loop executes forever. 开发者_JAVA技巧Please help.

 children = [ ]
 children.append(documentElement.firstChild())
 curr_node = children[0]
 while curr_node.nextSibling():
     print curr_node, len(children)
     children.append(curr_node.nextSibling())
     curr_node = curr_node.nextSibling()


As i understand nextSibling will always return a QWebElement, however you can check if that is a null element using isNull()

while not curr_node.nextSibling().isNull():
     print curr_node, len(children)
     children.append(curr_node.nextSibling())
     curr_node = curr_node.nextSibling()

You can check that in http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwebelement.html#isNull http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwebelement.html#nextSibling

0

精彩评论

暂无评论...
验证码 换一张
取 消