@Override public void head(final Node node, final int depth) { try { if (node instanceof Document) { handler.startDocument(); } else if (node instanceof Element) { final Element e = (Element) node; final org.xml.sax.Attributes attributes = convertAttributes(e.attributes()); handler.startElement(NS, e.tagName(), e.tagName(), attributes); } else if (node instanceof TextNode) { final TextNode t = (TextNode) node; final char[] c = t.toString().toCharArray(); handler.characters(c, 0, c.length); } } catch (final SAXException e) { LOGGER.warn("Fail to open tag", e); } }
private static Follow parse(Element followEl, String followerID, int currentLevel) { Follow follow = new Follow(); try { int fansOfFollowee = 0; for (TextNode text : followEl.getElementsByTag("td").get(1).textNodes()) { if (text.toString().startsWith("粉丝")) { int startIndex = "粉丝".length(); int endIndex = text.toString().indexOf("人"); fansOfFollowee = Integer.parseInt(text.toString().substring(startIndex, endIndex)); } } // 根据fansOfFollowee进行过滤 String followeeUrl = followEl.getElementsByTag("img").get(0).attr("src"); String followeeID = Utils.getUserIdFromImgUrl(followeeUrl); follow.setFollower(followerID); follow.setFollowed(followeeID); follow.setLevel(currentLevel); } catch (Exception e) { follow = null; logger.error("Not a valid follow item: " + followEl, e); } return follow; }