python QtWebkit:nextSibing 不返回 null 或 None
下面是我用来获取给定节点的所有子节点的列表的代码片段。但是 nextSibling() 永远不会返回 null,因此 while 循环会永远执行。请帮忙。
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()
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. 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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解 nextSibling 将始终返回 QWebElement,但是您可以使用 isNull() 检查它是否为 null 元素
您可以在 http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwebelement.html#isNull
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwebelement.html#nextSibling
As i understand nextSibling will always return a QWebElement, however you can check if that is a null element using isNull()
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