Java HTML Parse Jsoup parseTemplate1_1(Element element)

Here you can find the source of parseTemplate1_1(Element element)

Description

parse Templat_

License

Apache License

Declaration

public static synchronized void parseTemplate1_1(Element element)
            throws JSONException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.json.JSONException;
import org.json.JSONObject;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Main {
    public static synchronized void parseTemplate1_1(Element element)
            throws JSONException {
        JSONObject jsonObject = new JSONObject();
        JSONObject jsonItem = new JSONObject();
        Element infotemplatebox = element.getElementsByClass(
                "infotemplatebox").first();
        Elements elements = infotemplatebox.select("tr");
        for (int i = 0, total = elements.size(); i < total; i++) {
            Element item = elements.get(i);
            //            System.err.println(item);
            if (i == 0) {
                jsonObject.put("cover", item.select("img").attr("src"));
            } else if (i > total - 3) {
                if (i == total - 1) {
                    jsonItem.put(elements.get(i - 1).text(), item.text());
                }/*from   w  w w. j  ava 2  s .  com*/
            } else {
                Elements th = item.select("th");
                Elements td = item.select("td");
                if (th.size() == 0 || td.size() == 0) {
                    jsonObject.put(td.size() == 0 ? th.text() : td.text(),
                            jsonItem);
                } else {
                    jsonItem.put(th.text(), td.text());
                }
            }
        }

        System.err.println(jsonObject.toString());

        element.getElementsByClass("infoBox").remove();
        element.getElementsByClass("infotemplatebox").remove();
        elements = element.select("p");

        //        System.err.println(elements.text());
    }
}

Related

  1. parseFile(String filePath)
  2. parseInfoBody(Element element)
  3. parseInfoHeader(Element element)
  4. parsePropertyTable(Element table)
  5. parseTable2ArrayList(Document doc, String selectorRow, String selectorCol)
  6. parseTemplate1_2(Element element)
  7. parseUTF8HTMLDocument(String html)
  8. parseWithAdultCheck(URL url, int timeout)
  9. prettyPrint(String html)