使用Curl获取表数据

时间:2017-01-21 12:02:22

标签: android html parsing jsoup

我需要解析网站上的数据,这个请求给了我在命令行中运行时需要的json,当我尝试将其转换为Android时,它无法正常工作:

  

我的要求:" curl' http://billetterie.ctm.ma/site/select_voyages_aller?datev=21-01-2017&agen_dep=022&agen_dest=745&nbp=1&dater=21-01-2017&aller=AS&tpay=MA&q=1&_search=false&nd=1485004301429&rows=30&page=1&sidx=&sord='   -H'主持人:billetterie.ctm.ma' -H' User-Agent:Mozilla / 5.0(X11; Ubuntu; Linux x86_64; rv:50.0)Gecko / 20100101 Firefox / 50.0' -H   '接受:application / json,text / javascript, / ; Q = 0.01' -H   '接受语言:en-US,en; q = 0.5' - 压缩-H' X-Requested-With:   XMLHttpRequest的' -H' Referer:   http://billetterie.ctm.ma/site/get_voyages?nat=1&tov1=nat&aller=AS&ag_dep=022&ag_arr=745&datev=21-01-2017&dater=21-01-2017&nbp=1&tpay=MA&horr=non'   -H' Cookie:__ utma = 155676777.794288111.1468961313.1473110615.1483191519.26; __utmz = 155676777.1472508246.19.2.utmcsr = billetterie.ctm.ma | utmccn =(引荐)| utmcmd =转诊| utmcct = /站点/ accueil_widget;   SESSb32ad49581ba1927701cb25c04e30aae = VhEOkLJ2qmLrlxEW3sNRIFpnS0ZUYPGUwAyvVqui_9I;   _ctm_site_session = BAh7BzoQX2NzcmZfdG9rZW4iMUJ1ZzFpN3JDdGlzaTJGZUZEY2F0SWZPK3hMOWhwWW1vSFJ5QnoyUXFWLzA9Og9zZXNzaW9uX2lkIiUwNmMxOTYxNGIzOTRmNzY2ZWY0YzkyYTVjNTc4MzQzYQ%3D%3D - 59c0a57e5935d23668767649d8483155f719faf8'   -H'连接:keep-alive'";

我的Java代码是:

 public static String getRequest(String url) {
        StringBuffer stringBuffer = new StringBuffer("");
        BufferedReader bufferedReader = null;
        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet();

            URI uri = new URI(url);
            httpGet.setURI(uri);


            HttpResponse httpResponse = httpClient.execute(httpGet);
            InputStream inputStream = httpResponse.getEntity().getContent();
            bufferedReader = new BufferedReader(new InputStreamReader(
                    inputStream));

            String readLine = bufferedReader.readLine();
            while (readLine != null) {
                stringBuffer.append(readLine);
                stringBuffer.append("\n");
                readLine = bufferedReader.readLine();
            }
        } catch (Exception e) {
            // TODO: handle exception
        } finally {
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    // TODO: handle exception
                }
            }
        }
        return stringBuffer.toString();

    }

1 个答案:

答案 0 :(得分:0)

我认为你不能同步解析这个页面,它不是JSOUP问题或HttpClient问题。

我能想到的唯一方法是浏览您的链接页面,并在该页面中异步完成请求。如果你需要的是表格内容,你需要解析的不是起始页面。

您需要的是找到执行异步调用以在浏览器上填充该表,进行该调用并尝试解析响应