Почему .select ("div.class") в jsoup не работает для CNN.com? - PullRequest
4 голосов
/ 16 мая 2019

Я пытался выяснить, почему .select ("div.zn-body__paragraph") для jsoup не работал над некоторыми статьями CNN. Для таких статей, как this , он не работает, несмотря на наличие этого тега, в то время как для таких статей, как this , работает. Вот полный код, который я написал:


    public static String getContentCNN(String link) throws IOException{
        String finalString = "";

        Elements paragraphs = getDocsCNN(link).select("div.zn-body__paragraph");

        for (Element p : paragraphs) {
            finalString += p.text() + "\n\n";
        }


        return finalString;
    }

У них обоих есть такие классы делителей:


<div class="zn-body__paragraph">Nadler on Wednesday said he didn't know the White House's motives, but he would not allow the White House to try to claim that the President cannot be held accountable.</div>

<div class="zn-body__paragraph">"I don't know whether they're trying to taunt us toward an impeachment or anything else," Nadler said. "All I know is they have made a preposterous claim."</div>

Пока что я пробовал div # class, div [class] и getElementByClass ("class")

Спасибо.

РЕДАКТИРОВАТЬ: Вот исходный код для getDocsCNN ():


public static Document getDocsCNN(String link) throws IOException{

        return Jsoup.connect(link).userAgent("Mozilla").timeout(6000).get();

    }

...