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
精彩评论