Search in sources :

Example 6 with Element

use of org.jsoup.nodes.Element in project useful-java-links by Vedenin.

the class GithubDownLoadTests method printElements.

private static void printElements(Elements children) {
    for (Element child : children) {
        if (!child.text().isEmpty()) {
            System.out.print(child.tag().getName() + " : ");
            System.out.println(child.text());
        }
        printElements(child.children());
    }
}
Also used : Element(org.jsoup.nodes.Element)

Example 7 with Element

use of org.jsoup.nodes.Element in project useful-java-links by Vedenin.

the class URLDownloadTests method printElements.

private static void printElements(Elements children) {
    for (Element child : children) {
        if (!child.text().isEmpty()) {
            System.out.print(child.tag().getName() + " : ");
            System.out.println(child.text());
        }
        printElements(child.children());
    }
}
Also used : Element(org.jsoup.nodes.Element)

Example 8 with Element

use of org.jsoup.nodes.Element in project ZhihuDailyPurify by izzyleung.

the class NewsListFromZhihuObservable method getQuestions.

private static List<Question> getQuestions(Document document, String dailyTitle) {
    List<Question> result = new ArrayList<>();
    Elements questionElements = getQuestionElements(document);
    for (Element questionElement : questionElements) {
        Question question = new Question();
        String questionTitle = getQuestionTitleFromQuestionElement(questionElement);
        String questionUrl = getQuestionUrlFromQuestionElement(questionElement);
        // Make sure that the question's title is not empty.
        questionTitle = TextUtils.isEmpty(questionTitle) ? dailyTitle : questionTitle;
        question.setTitle(questionTitle);
        question.setUrl(questionUrl);
        result.add(question);
    }
    return result;
}
Also used : Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Question(io.github.izzyleung.zhihudailypurify.bean.Question) Elements(org.jsoup.select.Elements)

Example 9 with Element

use of org.jsoup.nodes.Element in project jsoup by jhy.

the class W3CDomTest method handlesInvalidAttributeNames.

@Test
public void handlesInvalidAttributeNames() {
    String html = "<html><head></head><body style=\"color: red\" \" name\"></body></html>";
    org.jsoup.nodes.Document jsoupDoc;
    jsoupDoc = Jsoup.parse(html);
    Element body = jsoupDoc.select("body").first();
    // actually an attribute with key '"'. Correct per HTML5 spec, but w3c xml dom doesn't dig it
    assertTrue(body.hasAttr("\""));
    assertTrue(body.hasAttr("name\""));
    Document w3Doc = new W3CDom().fromJsoup(jsoupDoc);
}
Also used : Element(org.jsoup.nodes.Element) Document(org.w3c.dom.Document) Test(org.junit.Test) ParseTest(org.jsoup.integration.ParseTest)

Example 10 with Element

use of org.jsoup.nodes.Element in project jsoup by jhy.

the class ParseTest method testYahooJp.

@Test
public void testYahooJp() throws IOException {
    File in = getFile("/htmltests/yahoo-jp.html");
    // http charset is utf-8.
    Document doc = Jsoup.parse(in, "UTF-8", "http://www.yahoo.co.jp/index.html");
    assertEquals("Yahoo! JAPAN", doc.title());
    Element a = doc.select("a[href=t/2322m2]").first();
    assertEquals("http://www.yahoo.co.jp/_ylh=X3oDMTB0NWxnaGxsBF9TAzIwNzcyOTYyNjUEdGlkAzEyBHRtcGwDZ2Ex/t/2322m2", // session put into <base>
    a.attr("abs:href"));
    assertEquals("全国、人気の駅ランキング", a.text());
}
Also used : Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Aggregations

Element (org.jsoup.nodes.Element)343 Document (org.jsoup.nodes.Document)152 Elements (org.jsoup.select.Elements)95 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)87 IOException (java.io.IOException)63 File (java.io.File)62 ArrayList (java.util.ArrayList)45 Test (org.junit.Test)34 TestSolutionHandler (org.asqatasun.ruleimplementation.TestSolutionHandler)21 URL (java.net.URL)15 TestSolutionHandlerImpl (org.asqatasun.ruleimplementation.TestSolutionHandlerImpl)15 SimpleElementSelector (org.asqatasun.rules.elementselector.SimpleElementSelector)13 TestSolution (org.asqatasun.entity.audit.TestSolution)11 HashMap (java.util.HashMap)9 ElementSelector (org.asqatasun.rules.elementselector.ElementSelector)9 Node (org.jsoup.nodes.Node)9 InputStream (java.io.InputStream)8 EvidenceElement (org.asqatasun.entity.audit.EvidenceElement)8 SSPHandler (org.asqatasun.processor.SSPHandler)7 ProcessRemarkService (org.asqatasun.service.ProcessRemarkService)7