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>*/
  • 相关阅读:
    python基础(1)#1,2,3,4可组成多少不重复的三位数
    HTML/CSS 学习笔记
    (转) 杨元:CSS浮动(float,clear)通俗讲解
    前端:HTML
    Servlet
    Maven 安装
    单例模式
    项目随笔
    树状结构--迭代
    DB的封装
  • 原文地址:https://www.cnblogs.com/androidxufeng/p/3707162.html
Copyright © 2011-2022 走看看