Python QtWebkit: nextSibing не возвращает ноль или None - PullRequest
0 голосов
/ 23 апреля 2011

Ниже приведен фрагмент кода, который я использую для получения списка всех дочерних элементов данного узла. Но nextSibling () никогда не возвращает ноль, поэтому цикл 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()

1 Ответ

2 голосов
/ 24 апреля 2011

Как я понимаю, nextSibling всегда будет возвращать QWebElement, однако вы можете проверить, является ли это нулевым элементом, используя isNull ()

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

Вы можете проверить это в http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwebelement.html#isNull http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwebelement.html#nextSibling

...