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

标签 android instagram

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

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 调试它时,String source 是空的。

最佳答案

使用 Jsoup 进行 HTML 解析。它非常简单和方便。 从这个答案开始并遵循文档 link

关于android - 如何下载 Instagram 页面的 HTML 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34397346/

相关文章:

android - 获取大量应用程序图标会导致内存不足

javascript - 如何在使用 Instagram API 时在 Meteor 中请求、存储和使用访问 token

javascript - 无法解析从 Instagram API 返回的 user_media 对象

objective-c - Instagram 如何将 UIKeyboard returnKey 自定义为 '@' 和 '#"?

node.js - 如何在 NodeJS 中获取 Instagram 用户名和访问 token

Instagram api thumb_url 给出 5xx 服务器错误

android - 如何使用 google api 为英特尔 x86 原子图像创建 avd?

android - 使用 Retrofit2 和 Kotlin : Unable to create call adapter 在正文中发布数据

android - 向客户端请求 OkHttp 添加 cookie

java - Eclipse, ImageView 上的 View 布局