Example usage for org.jsoup.nodes Document select

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

Introduction

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

Prototype

public Elements select(String cssQuery) 

Source Link

Document

Find elements that match the Selector CSS query, with this element as the starting context.

Usage

From source file:com.johan.vertretungsplan.additionalinfo.WinterShParser.java

@Override
public AdditionalInfo getAdditionalInfo() throws IOException, JSONException {
    AdditionalInfo info = new AdditionalInfo();
    String xml = httpGet(URL, ENCODING);
    Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
    String text = doc.select("item description").first().text();
    if (text.contains("Aktuell gibt es keine Hinweise auf witterungsbedingten Unterrichtsausfall.")) {
        text = "keine Informationen";
        info.setHasInformation(false);/*from  www  . ja v  a  2 s  . c o m*/
    }
    info.setText(text);
    info.setTitle(TITLE + " (Stand: " + doc.select("pubDate").first().text() + ")");
    return info;
}

From source file:com.sastix.cms.server.services.content.impl.GeneralFileHandlerServiceImpl.java

@Override
public String findParentFile(String xml) {
    String ret = null;//  w  w w .  j ava2  s.  c  o m
    Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
    for (Element e : doc.select("resources")) {
        ret = e.select("resource").get(0).attr("href");
    }
    return ret;
}

From source file:org.cellcore.code.engine.page.extractor.mfrag.MFRAGPageDataExtractor.java

@Override
protected String getName(Document doc) throws UnsupportedCardException {
    String name = doc.select(".prod-det_s-titre-gb").text();
    return name;//from www  .  j a v  a2 s .  c o  m
}

From source file:org.cellcore.code.engine.page.extractor.mcc.MCCPageDataExtractor.java

@Override
protected float getPrice(Document doc) {
    Elements tr = doc.select("#blockContent").get(5).select("tr");
    float iPrice = Float.MAX_VALUE;
    for (int i = 0; i < tr.size(); i++) {
        try {/*w  w w .j a  va 2 s . c o  m*/
            String val = tr.get(i).getElementsByTag("td").get(3).childNodes().get(0).attr("text");
            val = cleanPriceString(val);
            float price = Float.parseFloat(val);
            if (price < iPrice) {
                iPrice = price;
            }
        } catch (Throwable t) {

        }
    }
    if (iPrice == Float.MAX_VALUE) {
        iPrice = -1;
    }
    return iPrice;
}

From source file:org.cellcore.code.engine.page.extractor.mcc.MCCPageDataExtractor.java

@Override
protected int getStock(Document doc) {
    Elements tr = doc.select("#blockContent").get(5).select("tr");
    float iPrice = Float.MAX_VALUE;
    int iStock = 0;
    for (int i = 0; i < tr.size(); i++) {
        try {/*ww w  .ja v  a2 s . co m*/
            String val = tr.get(i).getElementsByTag("td").get(3).childNodes().get(0).attr("text");
            String stockV = tr.get(i).getElementsByTag("td").get(4).select("option").last().childNodes().get(0)
                    .attr("text");
            val = cleanPriceString(val);
            float price = Float.parseFloat(val);
            if (price < iPrice) {
                iPrice = price;
                iStock = Integer.parseInt(stockV.replaceAll("\\(", "").replaceAll("\\)", ""));
            }
        } catch (Throwable t) {

        }
    }
    return iStock;
}

From source file:org.cellcore.code.engine.page.extractor.mb.MBPageDataExtractor.java

protected String getName(Document doc) throws UnsupportedCardException {

    return doc.select(".text").get(2).childNodes().get(0).attr("text").trim();
}

From source file:it.polito.tellmefirst.web.rest.apimanager.VideoManager.java

public String extractVideoIdFromResult(String input) {
    LOG.debug("[extractVideoIdFromResult] - BEGIN");
    String result;//from www .  j a v a2s  . c  om
    Document doc = Jsoup.parse(input);
    String idDirty = doc.select("id").get(1).text();
    System.out.println("ID dirty: " + idDirty);
    String[] idArray = idDirty.split("video:");
    result = idArray[idArray.length - 1];
    LOG.debug("[extractVideoIdFromResult] - END");
    return result;
}

From source file:org.sonatype.nexus.testsuite.misc.nxcm4389.NXCM4389FavIconIT.java

@Test
public void testFavicons() throws IOException {
    // assert that shortcut icon mentioned in the HTML is actually available
    final String text = RequestFacade.doGetForText("index.html");
    Document doc = Jsoup.parse(text);
    RequestFacade.doGetForStatus(doc.select("link[rel=icon]").attr("href"), NexusRequestMatchers.isSuccess());
    doc = extractIELink(doc);/*www  .jav a2s .  c  o m*/

    RequestFacade.doGetForStatus(doc.select("link[rel=shortcut icon]").attr("href"),
            NexusRequestMatchers.isSuccess());
}

From source file:it.polito.tellmefirst.web.rest.apimanager.ImageManager.java

public String scrapeImageFromPage(String pageURL) {
    LOG.debug("[scrapeImageFromPage] - BEGIN");
    String result = Enhancer.DEFAULT_IMAGE;
    try {// w w w. j  a  va 2 s .co m
        Document doc = Jsoup.connect(pageURL).get();
        Element image = doc.select("div.fullImageLink").select("img").first();
        result = image.attr("src");
    } catch (Exception e) {
        LOG.error("[scrapeImageFromPage] - EXCEPTION: ", e);
    }
    LOG.debug("[scrapeImageFromPage] - END");
    return result;
}

From source file:it.polito.tellmefirst.web.rest.apimanager.ImageManager.java

public String scrapeDBpediaImageFromPage(String pageURL) {
    LOG.debug("[scrapeDBpediaImageFromPage] - BEGIN");
    String result = "";
    try {/* www. j a va2  s . c o m*/
        Document doc = Jsoup.connect(pageURL).get();
        Element image = doc.select("div.fullImageLink").select("img").first();
        result = "http:" + image.attr("src");
    } catch (Exception e) {
        LOG.error("[scrapeDBpediaImageFromPage] - EXCEPTION: ", e);
    }
    LOG.debug("[scrapeDBpediaImageFromPage] - END");
    return result;
}