简体   繁体   中英

Problems with parsing facebook using Jsoup

I wrote a program to parse facebook, and I can get the whole DOM tree already. Things go well but when I want to select all <p> -tags, the problem is it returns a zero sized array. PS: Nothing goes wrong when I parse other websites but facebook.

Here is my code:

public static void main(String[] args) throws IOException {
    doc = connect(); //connect the website,
    System.out.print(doc.outerHtml());//in the wole html file, i can find the tag <p>
    newsHeadlines = doc.select("p"); //nothing
    doc.getElementsByTag("p");//nothing either
    oldEleStr = newsHeadlines.text();
    System.out.println(oldEleStr);//nothing
}


static Document connect() throws IOException {
    org.jsoup.Connection connection = Jsoup
            .connect("facebook.com")
            .cookies(
                    splitCookies(facebookCookies));
    Document doc = connection.get();
    return doc;
}

You may want to try something like:

Document new_doc = Jsoup.parse(doc.outerHtml());
Elements elements = doc.select("p");
for (Element aa : elements) {
    //TODO:
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM