htmlparser日记

时间:2023-01-11 21:12:10

myParser = Parser.createParser(response, "utf-8");
NodeFilter tableFilter = new NodeClassFilter(Div.class);
OrFilter lastFilter = new OrFilter();
lastFilter.setPredicates(new NodeFilter[] { tableFilter });
try {
// 获取标签为div的节点列表
nodeList = myParser.parse(lastFilter);

// 循环读取每个div
for (int i = 0; i <= nodeList.size(); i++) {
if (nodeList.elementAt(i) instanceof Div) {
// System.out.println(nodeList.elementAt(i));
Div tag = (Div) nodeList.elementAt(i);

if ((tag.getAttribute("class") != null)
&& (tag.getAttribute("class")
.equals("aaaaaa"))) {