//下面是htmlparser查找余额方法 // String html = this.postValuesFor3yx(LOGIN,HYZX,userName,passWord); // Parser parser=Parser.createParser(html, "gbk"); // NodeFilter filter=new AndFilter(new TagNameFilter("span"), new HasAttributeFilter("class", "bold cor_3366CC")); // List<String> remainingMoneys=new ArrayList<String>(); // try { // NodeList nodelist=parser.extractAllNodesThatMatch(filter); // Node[] nodes = nodelist.toNodeArray(); // for (Node node : nodes) { // remainingMoneys.add(node.getChildren().elementAt(0).toHtml()); // } // return remainingMoneys.size()>0?remainingMoneys.get(0):null; // } catch (ParserException e) { // e.printStackTrace(); // } // return null; //正则表达式 // String html = this.postValuesFor3yx(LOGIN,HYZX,userName,passWord); // String extractRegText = ""; // String userWalletAmount = ""; // try { // extractRegText = extractRegText(html, "可用余额:.+?元"); // //System.out.println(extractRegText); // userWalletAmount = extractRegText(extractRegText, ">.+?<"); // userWalletAmount = extractRegText(userWalletAmount,"\\d+(.\\d{2})?"); // return new String(userWalletAmount); // } catch (MalformedPatternException e1) { // e1.printStackTrace(); // } // return null; public static String extractRegText(String source, String regxp) throws MalformedPatternException { if (source == null) { return ""; } Pattern pattern = new Perl5Compiler().compile(regxp, Perl5Compiler.READ_ONLY_MASK); Perl5Matcher matcher = new Perl5Matcher(); if (matcher.contains(source, pattern)) { return matcher.getMatch().toString(); } return ""; } |
|