我需要從網站解析數據,這個請求爲我提供了當我在命令行中運行它時需要的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)壁虎/ 20100101 Firefox/50.0'-H 'Accept:application/json,text/javascript,/; q = 0.01'-H 'Accept-Language:en-US,en; q = 0.5'--compressed -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 '連接:保持活動'「;
我對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();
}
這是什麼分析?你在哪裏啓動url變量? – firegloves
我在啓動這個線程之前初始化了url變量,我發現只有標題和相同的段落不像我的導航器中的鏈接那樣,我希望我回答了您的問題 –
似乎數據加載到表中是異步加載的。如果你打開你的鏈接,你可以看到加載器。使用jsoup你不會等待異步調用,所以你的表是空的或者還沒有創建 – firegloves