Search in sources :

Example 96 with Elements

use of org.jsoup.select.Elements in project charts by vaadin.

the class ChartDesignReaderTest method readConfiguration_multiValueNodes_allTheNodesAreInTheConfiguration.

@Test
public void readConfiguration_multiValueNodes_allTheNodesAreInTheConfiguration() {
    Elements elements = createElements("<y-axis><chart-title>First</chart-title></y-axis>" + "<y-axis><chart-title>Second</chart-title></y-axis>");
    Configuration configuration = new Configuration();
    ChartDesignReader.readConfigurationFromElements(elements, configuration);
    assertEquals(2, configuration.getyAxes().getNumberOfAxes());
    assertEquals("First", configuration.getyAxis(0).getTitle().getText());
    assertEquals("Second", configuration.getyAxis(1).getTitle().getText());
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 97 with Elements

use of org.jsoup.select.Elements in project mzzb-server by mingzuozhibi.

the class SakuraSpeedSpider method fetch.

public void fetch() throws IOException {
    Document document = Jsoup.connect(SAKURA_SPEED_URL).timeout(30000).get();
    Elements tables = document.select("table");
    Elements fonts = document.select("b>font[color=red]");
    for (int i = 0; i < tables.size(); i++) {
        updateSakura(tables.get(i), fonts.get(i).text());
    }
}
Also used : Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Example 98 with Elements

use of org.jsoup.select.Elements in project Palm300Heroes by nicolite.

the class NewsModel method getTyBannerNiang.

public static List<NewsBanner> getTyBannerNiang(Document document) {
    List<NewsBanner> list = new ArrayList<>();
    Elements niang = document.body().getElementsByClass("niang");
    Elements img = niang.select("img");
    Elements a = niang.select("a");
    for (int i = 0; i < Math.min(a.size(), img.size()); i++) {
        NewsBanner newsBanner = new NewsBanner();
        newsBanner.setUrl(a.get(i).attr("abs:href"));
        String url = img.get(i).attr("style").replace("background: url(", "").replace(") no-repeat center;", "").trim();
        newsBanner.setImage(url);
        newsBanner.setTitle(" ");
        list.add(newsBanner);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) NewsBanner(cn.nicolite.palm300heroes.model.bean.NewsBanner) Elements(org.jsoup.select.Elements)

Example 99 with Elements

use of org.jsoup.select.Elements in project Palm300Heroes by nicolite.

the class NewsModel method getTYAVideoContent.

public static String getTYAVideoContent(Document document) {
    Element body = document.body();
    Element head = document.head();
    Elements inner = body.getElementsByClass("inner");
    Elements images = inner.select("img[src]");
    for (Element element : images) {
        element.removeAttr("style");
        element.attr("src", element.attr("abs:src"));
    }
    Elements span = inner.select("span");
    for (Element element : span) {
        element.removeAttr("style");
    }
    Elements p = inner.select("p");
    for (Element element : p) {
        element.removeAttr("style");
    }
    Elements div = inner.select("div");
    for (Element element : div) {
        element.removeAttr("style");
    }
    Elements h1 = inner.select("h1");
    for (Element element : h1) {
        element.removeAttr("style");
    }
    Elements h2 = inner.select("h2");
    for (Element element : h2) {
        element.removeAttr("style");
    }
    Elements h3 = inner.select("h3");
    for (Element element : h3) {
        element.removeAttr("style");
    }
    Elements h4 = inner.select("h4");
    for (Element element : h4) {
        element.removeAttr("style");
    }
    Elements h5 = inner.select("h5");
    for (Element element : h5) {
        element.removeAttr("style");
    }
    Elements h6 = inner.select("h6");
    for (Element element : h6) {
        element.removeAttr("style");
    }
    head.empty();
    head.append("  <meta charset=\"utf-8\">" + "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">" + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" + "<style type=\"text/css\">img{width: 100%; height: 100%; object-fit: contain}</style>");
    body.empty();
    body.append(inner.toString());
    String html = document.toString().replace("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">", "<!DOCTYPE html>").replace("xmlns=\"http://www.w3.org/1999/xhtml\"", "");
    LogUtils.d(TAG, html);
    return html;
}
Also used : Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 100 with Elements

use of org.jsoup.select.Elements in project Palm300Heroes by nicolite.

the class NewsModel method getTYBannerA.

// http://300c.jumpw.com/
public static List<NewsBanner> getTYBannerA(Document document) {
    List<NewsBanner> list = new ArrayList<>();
    Elements ad_gd = document.body().getElementsByClass("ad_gd");
    Elements a = ad_gd.select("a");
    Elements img = ad_gd.select("img");
    for (int i = 0; i < Math.min(a.size(), img.size()); i++) {
        NewsBanner newsBanner = new NewsBanner();
        newsBanner.setUrl(a.get(i).attr("abs:href"));
        String url = img.get(i).attr("style").replace("background: url(", "").replace(") no-repeat center;", "").trim();
        newsBanner.setImage(url);
        newsBanner.setTitle(" ");
        list.add(newsBanner);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) NewsBanner(cn.nicolite.palm300heroes.model.bean.NewsBanner) Elements(org.jsoup.select.Elements)

Aggregations

Elements (org.jsoup.select.Elements)709 Element (org.jsoup.nodes.Element)490 Document (org.jsoup.nodes.Document)362 ArrayList (java.util.ArrayList)213 IOException (java.io.IOException)151 Test (org.junit.Test)110 URL (java.net.URL)58 List (java.util.List)47 Matcher (java.util.regex.Matcher)42 Pattern (java.util.regex.Pattern)34 HashMap (java.util.HashMap)30 InputStream (java.io.InputStream)29 Jsoup (org.jsoup.Jsoup)28 Configuration (com.vaadin.addon.charts.model.Configuration)27 File (java.io.File)26 JSONObject (org.json.JSONObject)26 JSONException (org.json.JSONException)25 Collectors (java.util.stream.Collectors)23 URISyntaxException (java.net.URISyntaxException)22 BootstrapContext (com.vaadin.flow.server.BootstrapHandler.BootstrapContext)20