就是按IE的F12后得到的网页源代码,
例如:
http://odds.500.com/fenxi/yazhi_same.php?cid=5&cp=平手/半球&id=384285&s1=0.800&s2=0.960
这个网页,我想得到的内容在源代码中是这样的,
<tr id="lodingtr"><td colspan="12">数据加载中,请稍候....</td></tr>
求教,如何获取这部分的内容,谢谢! 爬虫javajsajax

解决方案 »

  1.   

    楼主的需求是不是只要获取ajax请求返回的那些数据啊,如果是的话你看下它ajax请求到哪个地址上传什么参数过去,你模拟他用httpURLConnection请求哪个ajax的地址传同样的参数过去就可以获取那段内容了
      

  2.   

    用程序模拟该http请求,得到返回的页面代码后用正则表达式分割出你想要的部分
            java.net.URL l_url = new java.net.URL("http://odds.500.com/fenxi/yazhi_same.php?cid=5&cp=平手/半球&id=384285&s1=0.800&s2=0.960");    
                    java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url.openConnection();    
                    l_connection.connect();    
                    l_urlStream = l_connection.getInputStream();    
                    java.io.BufferedReader l_reader = new java.io.BufferedReader(new java.io.InputStreamReader(l_urlStream));   
                   //str就是页面代码,用split函数和正则表达式分割str
                    String str=l_reader.readLine(); 
      

  3.   

    仅供参考/**
     * 获取某个网页的内容
     * @param url  网页的地址
     * @param code 网页的编码,不传就代表UTF-8
     * @return 网页的内容
     * @throws IOException
     */
    public static String fetch_url(String url, String code) throws IOException {
    BufferedReader bis = null; 
        InputStream is = null; 
        InputStreamReader inputStreamReader = null;
        try { 
            URLConnection connection = new URL(url).openConnection(); 
            connection.setConnectTimeout(20000);
            connection.setReadTimeout(20000);
            connection.setUseCaches(false);
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11");
            is = connection.getInputStream(); 
            inputStreamReader = new InputStreamReader(is, code);
            bis = new BufferedReader(inputStreamReader); 
            String line = null; 
            StringBuffer result = new StringBuffer(); 
            while ((line = bis.readLine()) != null) { 
                result.append(line); 
            } 
           
            return result.toString(); 
        } finally { 
         if (inputStreamReader != null) {
         try { 
         inputStreamReader.close();
                } catch (IOException e) { 
                    e.printStackTrace(); 
                } 
        
         }
            if (bis != null) { 
                try { 
                    bis.close(); 
                } catch (IOException e) { 
                    e.printStackTrace(); 
                } 
            } 
            if (is != null) { 
                try { 
                    is.close(); 
               } catch (IOException e) { 
                    e.printStackTrace(); 
                } 
            } 
        } 
    }