Example usage for org.jsoup.nodes Document getElementsContainingText

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

Introduction

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

Prototype

public Elements getElementsContainingText(String searchText) 

Source Link

Document

Find elements that contain the specified string.

Usage

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

protected float getPrice(Document doc) {
    if (!doc.getElementsContainingText("Cette carte n'est pas disponible en stock").isEmpty()) {
        return -1;
    }//from   w w  w  .j a v  a2  s  . c  om
    Elements tr = doc.select(".stock").get(0).getElementsByTag("tr");
    float iPrice = Float.MAX_VALUE;
    for (int i = 1; i < tr.size(); i++) {
        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;
        }
    }
    return iPrice;
}

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

@Override
protected int getStock(Document doc) {
    if (!doc.getElementsContainingText("Cette carte n'est pas disponible en stock").isEmpty()) {
        return 0;
    }/*from   w w w  .  j ava 2 s.c om*/
    Elements tr = doc.select(".stock").get(0).getElementsByTag("tr");
    float iPrice = Float.MAX_VALUE;
    int iStock = 0;
    for (int i = 1; i < tr.size(); i++) {
        String val = tr.get(i).getElementsByTag("td").get(3).childNodes().get(0).attr("text");
        String stockV = tr.get(i).getElementsByTag("td").get(4).childNodes().get(1).attr("text");
        val = cleanPriceString(val);
        float price = Float.parseFloat(val);

        if (price < iPrice) {
            iPrice = price;
            iStock = Integer.parseInt(stockV.replaceAll("\\(", "").replaceAll("\\)", ""));
        }
    }
    return iStock;
}