1

I have done a lot of research, but I haven't got any success in this. I want to fetch comments on a specific post. I thought this site will surely help me out in this.

I did some code for the same but it is printing the main post, my requirement is to fetch the comments over a specific post. In this code I have used jsoup library.

Elements hiddenElements = doc.select("code.hidden_elem");
        for (Element hidden : hiddenElements) {
            for (Node child : hidden.childNodesCopy()) {
                if (child instanceof Comment) {
                    hidden.append(((Comment) child).getData());
                }
            }
        }

        Elements articles = doc.select("div[role=article]");
        for (Element article : articles) {
            if (article.select("span.userContent").size() > 0) {
                String text = article.select("span.userContent").text();
                String imgUrl = article.select("div.photo img").attr("abs:src");
                System.out.println(String.format("%s\n%s\n\n", text, imgUrl));
            }
        }

Help in this will be appreciated. :)

  • One answer: Facebook Graph API... When you have _that_, why would you scrape Facebook? – ppeterka Sep 25 '13 at 07:24
  • @ppeterka66 I want to get comments of a specific post as I have mentioned in my question. With the above code I am able to get only post on public pages and not comments. Do I need to add whole code? or the snippet is fine? – user2814027 Sep 25 '13 at 07:30
  • 2
    I think the whole approach is invalid: Check out [this answer](http://stackoverflow.com/questions/4791951/retrieve-facebook-post-comments-using-graph-api) to get a picture on how it works. Facebook provides a way to get the data you want in JSON format... – ppeterka Sep 25 '13 at 07:35

0 Answers0