1

in my app i need to download HTML source of an Instagram profile and parse it to get some information (media and followed-by count). That's my code (it works for all sites i tested, except for 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) {}

When i debug it with LogCat, String source is empty.

omeliiii
  • 31
  • 1
  • 4

1 Answers1

2

Use Jsoup for HTML parsing. It is quite easy and handy. Take start from this answer and follow documents link

Community
  • 1
  • 1
Zeeshan Shabbir
  • 6,704
  • 4
  • 38
  • 74