Android端解析html文件

使用的是 net.htmlparesr.jericho.Source;包中的Source,需要导入jaricho-html-3.1.jar的外部jar包

 

一下为用这个包解析豆瓣网站的验证码的代码

 1         URL url = new URL("http://www.douban.com/accounts/login");
 2         URLConnection conn  = url.openConnection();
 3         //得到服务器返回的html连接 转化成的html的对象
 4         Source source = new Source(conn);
 5         
 6         List<Element> inputElements = source.getAllElements("input");
 7         for(Element input: inputElements){
 8             if("captcha-id".equals(input.getAttributeValue("name"))){
 9                 String id  = input.getAttributeValue("value");
10                 String path = "http://www.douban.com/misc/captcha?id="+id+"&amp;size=s";
11                 System.out.println("验证码图片的地址为:"+path);
12             }
13         }

 

posted @ 2013-01-23 21:11  王世桢  阅读(493)  评论(0编辑  收藏  举报