【发布时间】:2012-10-11 07:27:31
【问题描述】:
我正在使用 HTMLDocument 迭代器来尝试迭代 HTMLDocument 中的所有 a 标记。但是,迭代器似乎跳过了嵌套在 p 标签内的标签。例如:
<html>
<body>
<a href = "somesite"> some site </a>
<p>
<a href = "someothersite"> some other site </a>
</p>
</body>
</html>
迭代器将获取第一个 a 标签(somesite),但不会转到 p 标签内的 a 标签(someothersite)。
代码如下:
private void getLinks() throws MalformedURLException {
HTMLDocument.Iterator it = content.getIterator(HTML.Tag.A);
it.next();
while(it.isValid()) {
// Do something
it.next();
}
}
有人可以提出原因吗?
【问题讨论】:
-
啊 - 原来是 it.next() 进入循环之前的第一个..