• Android 之Html的解析(使用jsoup)


        Runnable run=new Runnable() {
            
            @Override
            public void run() {
                // TODO Auto-generated method stub
                userinfos=new ArrayList<UserInfo>();
                
                HttpClient http=new DefaultHttpClient();
                HttpPost post=new HttpPost("http://lolbox.duowan.com/playerList.php");
                List<NameValuePair> parmas=new ArrayList<NameValuePair>();
                parmas.add(new BasicNameValuePair("keyWords", "菜鸟召唤师风哥哥"));
                try {
                    post.setEntity(new UrlEncodedFormEntity(parmas,HTTP.UTF_8));
                } catch (UnsupportedEncodingException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                try {
            
                HttpResponse response=http.execute(post);
                String result = EntityUtils.toString(response
                        .getEntity());
                //String作为输入源
                Document document=Jsoup.parse(result);
                //File文件作为输入源
                //File input = new File("/tmp/input.html");
                //Document doc = Jsoup.parse(input, "UTF-8", "http://www.example.com/");
                
                //String作为输入源
                //Document doc = Jsoup.connect("http://www.example.com").timeout(60000).get();
                
                Elements elements_url=document.select("td.left");
                Elements elements_texts=document.select("td");
                for(int i=0;i<elements_url.size();i++){
                    UserInfo userinfo=new UserInfo();
                    Element  element=elements_url.select("a").first();
                    Element  element_text=elements_texts.get(i*2+1);
                    String text=element_text.text();
                    String url=element.attr("href");
                    userinfo.setUrl(url);
                    userinfo.setArea(text);
                    userinfos.add(userinfo);
                    Log.d("ssss", url);
                    Log.d("ssss", text);
                }    
                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        };
        /*</tr>
    
        <tr>
            <th width="50%" class="left" scope="col">玩家名字</th>
            <th width="50%" scope="col">服务器</th>
        </tr>
    
                        <tr>
                <td class="left"><a href="playerDetail.php?serverName=%E7%94%B5%E4%BF%A1%E4%B8%89&playerName=%E8%8F%9C%E9%B8%9F%E5%8F%AC%E5%94%A4%E5%B8%88%E9%A3%8E%E5%93%A5%E5%93%A5">菜鸟召唤师风哥哥</a></td>
                <td >诺克萨斯 电信三</td>
            </tr>
                        <tr>
                <td class="left"><a href="playerDetail.php?serverName=%E7%94%B5%E4%BF%A1%E5%9B%9B&playerName=%E8%8F%9C%E9%B8%9F%E5%8F%AC%E5%94%A4%E5%B8%88%E9%A3%8E%E5%93%A5%E5%93%A5">菜鸟召唤师风哥哥</a></td>
                <td >班德尔城 电信四</td>
            </tr>
                </table>
        <!-- 分页{ -->
      <div class="center" >
        <div class="mod-page">
                    </div>*/
  • 相关阅读:
    用魔数防范文件上传攻击
    nginx http跳转到https
    tengine安装
    版本标记说明
    nginx基于域名的虚拟主机 反向代理配置实例
    非ROOT用户启动Tomcat
    使用druid连接池的超时回收机制排查连接泄露问题
    Jenkins入门系列之
    centos7 关闭SELINUX 防火墙
    mac安装IE浏览器
  • 原文地址:https://www.cnblogs.com/androidxufeng/p/3707162.html
Copyright © 2020-2023  润新知