zoukankan      html  css  js  c++  java
  • 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>*/
  • 相关阅读:
    git 拉取开发代码
    android webview
    H5 元素定位
    Python中模块
    服务器1
    活动
    宝塔面板-阿里部署
    最新版Xshell、Xftp注册机NetSarang
    最新版Navicat Premium激活,附激活工具
    9月29更新美版T-mobile版本iPhone7代和7P有锁机卡贴解锁方法
  • 原文地址:https://www.cnblogs.com/androidxufeng/p/3707162.html
Copyright © 2011-2022 走看看