我需要下載Instagram資料的HTML源代碼並解析它以獲取一些信息(媒體和後續計數)。 這是我的代碼(它適用於我測試的所有站點,除了Instagram的):如何在我的應用程序中下載Instagram頁面的HTML源代碼
try {
InputStream in;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if(!(conn instanceof HttpURLConnection))
throw new NoConnectionException("not instanceof http");
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
in = httpConn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
String source = "";
while((line = br.readLine()) != null)
source += line;
br.close();
} catch(Exception e) {}
當我的logcat調試它,絃樂來源是空的。
你可以張貼鏈接 – Mohit
首先「把httpclinet拿走並使用改造或凌空」 –
@sadeghsaati你在哪裏看到'HttpClient'這裏? – Henry