Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何下载Instagram页面的HTML源代码_Android_Instagram - Fatal编程技术网

Android 如何下载Instagram页面的HTML源代码

Android 如何下载Instagram页面的HTML源代码,android,instagram,Android,Instagram,在我的应用程序中,我需要下载Instagram配置文件的HTML源代码,并对其进行解析以获取一些信息(媒体和计数)。 这是我的代码(它适用于我测试的所有站点,Instagram除外): 当我用LogCat调试它时,字符串源是空的。使用Jsoup进行HTML解析。这很容易,也很方便。 从这个答案开始,按照文档进行操作首先“将httpclinet收起来并使用改装或截击”@sadeghsaati您在这里看到的HttpClient在哪里?也许您检索到了一个异常?您的catch块是emtpy,因此可能是无

在我的应用程序中,我需要下载Instagram配置文件的HTML源代码,并对其进行解析以获取一些信息(媒体和计数)。 这是我的代码(它适用于我测试的所有站点,Instagram除外):


当我用LogCat调试它时,字符串源是空的。

使用Jsoup进行HTML解析。这很容易,也很方便。
从这个答案开始,按照文档进行操作

首先“将httpclinet收起来并使用改装或截击”@sadeghsaati您在这里看到的
HttpClient
在哪里?也许您检索到了一个异常?您的catch块是emtpy,因此可能是无提示的。@Henry抱歉,我指的是HttpURLConnectionOk,但为什么我的代码适用于我测试的所有站点,而不适用于Instagram?您的代码看起来也不错。但是Jsoup非常简单。只需一行代码,您就拥有了所有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) {}