Example usage for org.jsoup.nodes Document toString

List of usage examples for org.jsoup.nodes Document toString

Introduction

In this page you can find the example usage for org.jsoup.nodes Document toString.

Prototype

public String toString() 

Source Link

Document

Gets this node's outer HTML.

Usage

From source file:Main.java

public static void main(String[] args) {
    String html = "<!html>" + "<html><body>" + "<span id='my'>" + "<span class=''contentTitle'>Director:</span>"
            + "<span>test</span></span>" + "</body></html>";

    Document doc = Jsoup.parse(html);
    System.out.println(doc.toString());

    Elements spanWithId = doc.select("span#my");

    if (spanWithId != null) {
        System.out.printf("Found %d Elements\n", spanWithId.size());

        if (!spanWithId.isEmpty()) {
            Iterator<Element> it = spanWithId.iterator();
            Element element = null;
            while (it.hasNext()) {
                element = it.next();/* w w w  . j a  v  a2 s. co  m*/
                System.out.println(element.toString());
            }
        }
    }
}

From source file:Main.java

public static void main(String... args) {
    String h = "<html><body>" + "<div><!-- foo --><p>bar<!-- baz --></div><!--qux--><br/></body></html>";
    Document doc = Jsoup.parse(h);
    removeComments(doc);/*  w  w  w .ja va 2 s .  co m*/
    System.out.println(doc.toString());
}

From source file:cognition.pipeline.service.anonymisation.AnonymisationService.java

public String pseudonymisePersonHTML(Individual individual, String text) {
    Document document = Jsoup.parse(text);
    traverseAndAnonymise(document, individual);
    return document.toString();
}

From source file:com.chang.mmp.controller.IndexController.java

@RequestMapping("/")
public ModelAndView welcome() {

    Document doc = InternetUtils.getContentByUrl("http://image.haosou.com/z?ch=wallpaper&listtype=hot");
    String res = doc.toString();
    String json = res.substring(res.indexOf("initData") + 10, res.indexOf("}]}}") + 4);
    // System.out.println(json);
    JSONObject jsonObject = JSONObject.fromObject(json);
    JSONObject jsonObject1 = JSONObject.fromObject(jsonObject.get("data").toString());
    // System.out.println("count------" + jsonObject1.getString("count"));
    JSONArray imgList = jsonObject1.getJSONArray("list");
    List<BgImage> biList = new ArrayList<BgImage>();
    for (int i = 0; i < imgList.size(); i++) {
        BgImage bi = new BgImage();
        JSONObject jo = imgList.getJSONObject(i);
        bi.setId(String.valueOf(i));
        bi.setUrl(jo.getString("cover_imgurl"));
        System.out.println(jo.getString("cover_imgurl"));
        bi.setName(StringUtils.unicodeToString(jo.getString("group_title")));
        bi.setDesc(StringUtils.unicodeToString(jo.getString("group_desc")));
        if (i == 0) {
            bi.setActive("1");
        } else {/*from   w w w  . j a va 2s.c  om*/
            bi.setActive("0");
        }
        biList.add(bi);
    }
    return new ModelAndView("view", "imgList", biList);
}

From source file:uk.ac.kcl.iop.brc.core.pipeline.dncpipeline.service.anonymisation.AnonymisationService.java

public String pseudonymisePersonHTML(Patient patient, String text) {
    Document document = Jsoup.parse(text);
    traverseAndAnonymise(document, patient);
    return document.toString();
}

From source file:coyote.dx.web.TestHtmlWorker.java

@Test
public void setHtmlGet() throws IOException {
    Resource resource = new Resource("http://localhost:" + port + "/data/test.html");
    Response response = resource.request();
    assertNotNull(response);/*from w  ww.  ja va2 s  . c  o m*/

    while (!response.isComplete()) {
        Thread.yield();
    }

    Document doc = response.getDocument();
    assertNotNull(doc);
    Elements elements = doc.getAllElements();
    System.out.println(doc.toString());
    System.out.println("Retrieved document contains " + elements.size() + " elements");
    assertTrue(elements.size() >= 40);
}

From source file:com.jaspersoft.android.jaspermobile.data.repository.report.page.HtmlPageCreator.java

@Override
@NonNull/*from w  w  w  .j  a va 2  s  .c o  m*/
public ReportPage create() throws Exception {
    String range = pageRequest.getRange();
    PageRange pageRange = PageRange.parse(range);

    ReportExportOptions options = ReportExportOptions.builder()
            .withFormat(ReportFormat.valueOf(pageRequest.getFormat())).withPageRange(pageRange).build();

    ReportExport export = execution.export(options);
    ReportExportOutput output = export.download();

    InputStream reportExport = output.getStream();
    InputStream customScript = context.getAssets().open("rest-report.js");

    try {
        Reader reader = new InputStreamReader(customScript);
        Template template = Mustache.compiler().compile(reader);

        int pageIndex = Integer.valueOf(range) - 1;
        Map<String, Object> data = new HashMap<>();
        data.put("jasperPrintName", execution.getExecutionId());
        data.put("pageIndex", pageIndex);
        data.put("isPro", server.isProEdition());
        String customJs = template.execute(data);

        DataNode indexHeadScript = DataNode.createFromEncoded("<script>" + customJs + "</script>", "");

        Document document = Jsoup.parse(reportExport, Charset.defaultCharset().name(), "");
        Elements head = document.getElementsByTag("head");
        head.append(indexHeadScript.toString());

        byte[] exportContent = document.toString().getBytes(Charset.forName("UTF-8"));
        return new ReportPage(exportContent, output.isFinal());
    } finally {
        IOUtils.closeQuietly(reportExport);
        IOUtils.closeQuietly(customScript);
    }
}

From source file:com.amastigote.xdu.query.module.WaterAndElectricity.java

@Override
public boolean checkIsLogin(@NotNull String username) throws IOException {
    Document document = getPage("", USEINFO_SUFFIX);
    if (document.toString().contains(username)) {
        ID = username;//from  w  ww.  j  a  v  a  2 s  .  c om
        return true;
    } else {
        ID = "";
        return false;
    }
}

From source file:com.amastigote.xdu.query.module.EduSystem.java

private @Nullable JSONObject personalInfoQuery() throws IOException, JSONException {
    if (!checkIsLogin(ID)) {
        return null;
    }/*  w w w . j  a  va 2s .co m*/

    URL url = new URL(SYS_HOST + "xjInfoAction.do?oper=xjxx");
    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
    httpURLConnection.setRequestProperty("Cookie", "JSESSIONID=" + SYS_JSESSIONID);
    httpURLConnection.connect();

    Document document = Jsoup.parse(httpURLConnection.getInputStream(), "gb2312",
            httpURLConnection.getURL().toString());
    document = Jsoup.parse(document.toString().replaceAll("&nbsp;", ""));

    Elements elements1 = document.select("td[width=275]");

    JSONObject jsonObject = new JSONObject();
    jsonObject.put(StudentKey.ID, elements1.get(0).text());
    jsonObject.put(StudentKey.NAME, elements1.get(1).text());
    jsonObject.put(StudentKey.GENDER, elements1.get(6).text());
    jsonObject.put(StudentKey.NATION, elements1.get(10).text());
    jsonObject.put(StudentKey.NATIVE_PLACE, elements1.get(11).text());
    jsonObject.put(StudentKey.DEPARTMENT, elements1.get(24).text());
    jsonObject.put(StudentKey.MAJOR, elements1.get(25).text());
    jsonObject.put(StudentKey.CLASS, elements1.get(28).text());

    return jsonObject;
}

From source file:com.amastigote.xdu.query.module.EduSystem.java

private @Nullable JSONObject gradesQuery() throws IOException, JSONException {
    if (!checkIsLogin(ID)) {
        return null;
    }/*  w w w  .j a  v a  2  s.c  o m*/

    URL url = new URL(SYS_HOST + GRADE_QUERY_SUFFIX);
    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
    httpURLConnection.setRequestProperty("Cookie", "JSESSIONID=" + SYS_JSESSIONID);
    httpURLConnection.connect();

    Document document = Jsoup.parse(httpURLConnection.getInputStream(), "gb2312",
            httpURLConnection.getURL().toString());
    document = Jsoup.parse(document.toString().replaceAll("&nbsp;", ""));

    JSONObject jsonObject = new JSONObject();
    Elements elements_content = document.select("td[class=pageAlign]");
    Elements elements_titles = document.select("b");
    for (int i = 0; i < elements_titles.size(); i++) {
        JSONObject jsonObject_semester = new JSONObject();
        String semester_key = elements_titles.get(i).text().trim();

        Element table_for_this_semester = elements_content.get(i);
        Elements elements_rows = table_for_this_semester.select("td[align=center]");

        for (int j = 0; j < elements_rows.size() / 7; j++) {
            JSONObject jsonObject_course = new JSONObject();
            String course_key = elements_rows.get(j * 7 + 2).text().trim();

            jsonObject_course.put(GradeKey.ID, elements_rows.get(j * 7).text().trim());
            jsonObject_course.put(GradeKey.CREDIT, elements_rows.get(j * 7 + 4).text().trim());
            jsonObject_course.put(GradeKey.ATTR, elements_rows.get(j * 7 + 5).text().trim());
            jsonObject_course.put(GradeKey.GRADE, elements_rows.get(j * 7 + 6).text().trim());
            jsonObject_semester.put(course_key, jsonObject_course);
        }
        jsonObject.put(semester_key, jsonObject_semester);
    }
    return jsonObject;
}