Search in sources :

Example 16 with Elements

use of org.jsoup.select.Elements in project jsoup by jhy.

the class HtmlParserTest method handlesUnclosedDefinitionLists.

@Test
public void handlesUnclosedDefinitionLists() {
    // jsoup used to create a <dl>, but that's not to spec
    String h = "<dt>Foo<dd>Bar<dt>Qux<dd>Zug";
    Document doc = Jsoup.parse(h);
    // no auto dl
    assertEquals(0, doc.select("dl").size());
    assertEquals(4, doc.select("dt, dd").size());
    Elements dts = doc.select("dt");
    assertEquals(2, dts.size());
    assertEquals("Zug", dts.get(1).nextElementSibling().text());
}
Also used : Elements(org.jsoup.select.Elements) Test(org.junit.Test) ParseTest(org.jsoup.integration.ParseTest)

Example 17 with Elements

use of org.jsoup.select.Elements in project jsoup by jhy.

the class HtmlParserTest method createsFormElements.

// form tests
@Test
public void createsFormElements() {
    String html = "<body><form><input id=1><input id=2></form></body>";
    Document doc = Jsoup.parse(html);
    Element el = doc.select("form").first();
    assertTrue("Is form element", el instanceof FormElement);
    FormElement form = (FormElement) el;
    Elements controls = form.elements();
    assertEquals(2, controls.size());
    assertEquals("1", controls.get(0).id());
    assertEquals("2", controls.get(1).id());
}
Also used : Elements(org.jsoup.select.Elements) Test(org.junit.Test) ParseTest(org.jsoup.integration.ParseTest)

Example 18 with Elements

use of org.jsoup.select.Elements in project jsoup by jhy.

the class HtmlParserTest method testSupportsNonAsciiTags.

@Test
public void testSupportsNonAsciiTags() {
    String body = "<進捗推移グラフ>Yes</進捗推移グラフ><русский-тэг>Correct</<русский-тэг>";
    Document doc = Jsoup.parse(body);
    Elements els = doc.select("進捗推移グラフ");
    assertEquals("Yes", els.text());
    els = doc.select("русский-тэг");
    assertEquals("Correct", els.text());
}
Also used : Elements(org.jsoup.select.Elements) Test(org.junit.Test) ParseTest(org.jsoup.integration.ParseTest)

Example 19 with Elements

use of org.jsoup.select.Elements in project AozoraEpub3 by hmdev.

the class WebAozoraConverter method getExtractText.

String getExtractText(Document doc, ExtractInfo[] extractInfos, boolean replace) {
    if (extractInfos == null)
        return null;
    for (ExtractInfo extractInfo : extractInfos) {
        String text = null;
        Elements elements = doc.select(extractInfo.query);
        if (elements == null || elements.size() == 0)
            continue;
        StringBuilder buf = new StringBuilder();
        if (extractInfo.idx == null) {
            for (Element element : elements) {
                String html = element.html();
                if (html != null)
                    buf.append(" ").append(replaceHtmlText(html, replace ? extractInfo : null));
            }
        } else {
            for (int i = 0; i < extractInfo.idx.length; i++) {
                if (elements.size() > extractInfo.idx[i]) {
                    int pos = extractInfo.idx[i];
                    //負の値なら後ろから
                    if (pos < 0)
                        pos = elements.size() + pos;
                    if (pos >= 0 && elements.size() > pos) {
                        String html = elements.get(pos).html();
                        if (html != null)
                            buf.append(" ").append(replaceHtmlText(html, replace ? extractInfo : null));
                    }
                }
            }
            if (buf.length() > 0)
                text = buf.deleteCharAt(0).toString();
        }
        //置換指定ならreplaceして返す
        if (text != null && text.length() > 0) {
            return text;
        }
    }
    return null;
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 20 with Elements

use of org.jsoup.select.Elements in project AozoraEpub3 by hmdev.

the class WebAozoraConverter method printRuby.

/** ルビを青空ルビにして出力 */
private void printRuby(BufferedWriter bw, Element ruby) throws IOException {
    Elements rb = ruby.getElementsByTag("rb");
    Elements rt = ruby.getElementsByTag("rt");
    if (rb.size() > 0) {
        if (rt.size() > 0) {
            bw.append('|');
            printText(bw, rb.get(0).text());
            bw.append('《');
            printText(bw, rt.get(0).text());
            bw.append('》');
        } else {
            printText(bw, rb.get(0).text());
        }
    }
}
Also used : Elements(org.jsoup.select.Elements)

Aggregations

Elements (org.jsoup.select.Elements)168 Element (org.jsoup.nodes.Element)96 Document (org.jsoup.nodes.Document)70 ArrayList (java.util.ArrayList)38 Test (org.junit.Test)33 IOException (java.io.IOException)24 URL (java.net.URL)13 ParseTest (org.jsoup.integration.ParseTest)11 File (java.io.File)9 List (java.util.List)8 HashMap (java.util.HashMap)7 SSPHandler (org.asqatasun.processor.SSPHandler)7 TestSolutionHandler (org.asqatasun.ruleimplementation.TestSolutionHandler)7 ProcessRemarkService (org.asqatasun.service.ProcessRemarkService)7 MalformedURLException (java.net.MalformedURLException)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 TextView (android.widget.TextView)4 RequestUtil (com.kyj.fx.voeditor.visual.util.RequestUtil)4 ResponseHandler (com.kyj.fx.voeditor.visual.util.ResponseHandler)4