Example usage for org.jsoup.select Elements toString

List of usage examples for org.jsoup.select Elements toString

Introduction

In this page you can find the example usage for org.jsoup.select Elements toString.

Prototype

@Override
public String toString() 

Source Link

Document

Get the combined outer HTML of all matched elements.

Usage

From source file:com.aestheticsw.jobkeywords.service.termextractor.impl.indeed.IndeedClient.java

/**
 * Return the job-details sub-section of the HTML that Indeed returns. This method takes a URL
 * that Indeed returns for each JobSummary returned by getIndeedJobSummaryList() above.
 * <p/>/*  ww  w.  j a  v  a2s.c  o m*/
 * 
 * This method is dependent upon the JSoup library which can consume malformed HTML and XML with
 * invalid syntax.
 * <p/>
 * 
 * JSoup can't be tested easily.
 * 
 * TODO convert from JSoup to HtmlCleaner
 */
public String getIndeedJobDetails(String url) {
    log.debug("Indeed job-details query: " + url);
    Document doc;
    try {
        doc = Jsoup.connect(url).get();
    } catch (IOException e) {
        throw new RuntimeException("Indeed-search or JSoup response parser failed, URL: " + url, e);
    }
    Elements jobHeader = doc.select("#job_header > b > font");
    Elements jobSummary = doc.select("#job_summary");
    StringBuilder sb = new StringBuilder();
    sb.append(jobHeader.toString()).append("\n");
    sb.append(jobSummary.toString());
    return sb.toString();
}

From source file:co.dilaver.quoter.fragments.QODFragment.java

private void parseQodResponse(JSONObject response) throws JSONException {
    JSONObject parse = response.getJSONObject("parse");
    JSONObject text = parse.getJSONObject("text");
    String content = text.getString("*");

    Document doc = Jsoup.parse(content);
    Elements table = doc.select("table[style=\"text-align:center; width:100%\"]");
    Elements rows = table.select("tr");
    Elements qod = rows.get(0).select("td");
    Elements author = rows.get(1).select("td");
    Whitelist whitelist = Whitelist.none();

    String newQuote = Html.fromHtml(Jsoup.clean(qod.toString(), whitelist)).toString();
    String newAuthor = Html.fromHtml(Jsoup.clean(author.toString(), whitelist).replace("~", "")).toString();

    if (!qodString.equals("") && !authorString.equals("")) {
        if (!qodString.equals(newQuote) || !authorString.equals(newAuthor)) {
            Snackbar.make(rootLayout, getString(R.string.str_Refreshing), Snackbar.LENGTH_SHORT).show();
        }//from   www.j a  va 2s.  co m
    }

    qodString = newQuote;
    authorString = newAuthor;

    sharedPrefStorage.setQodText(qodString);
    sharedPrefStorage.setQodAuthor(authorString);

    Log.e(TAG, "quote: " + qodString);
    Log.e(TAG, "author: " + authorString);

    qodText.setText(getString(R.string.str_WithinQuotation, qodString));
    qodAuthor.setText(authorString);
}

From source file:com.hp.test.framework.htmparse.UpdateTestCaseDesciption.java

public static void replaceDetailsTable(String path) throws IOException {

    File source = new File(path);
    Document report = null;//w  ww .  j  a v a2s.c o  m
    try {
        report = Jsoup.parse(source, "UTF-8");
    } catch (IOException e) {
        System.out.println("Unable to open [" + source.getAbsolutePath() + "] for parsing!");
    }
    Elements dom = report.children();
    Elements tds = report.select("table[id=tableStyle] td"); // select the tds from your table
    String temp_key = "";
    for (Element td : tds) { // loop through them

        String[] temp_ar = td.toString().split("\"");
        String Key = temp_ar[1];
        String Status = "";

        if (td.toString().contains("pass.png")) {
            Status = "pass";
        }
        if (td.toString().contains("fail.png")) {
            Status = "fail";
        }
        if (td.toString().contains("skip.png")) {
            Status = "skip";
        }

        if (TestCaseDesMap.containsKey(temp_key) && Status.length() > 1) {
            TestcaseStatusMap.put(temp_key, Status);
            temp_key = "";
        }

        if (td.text().contains("Test Method")) { // found the one you want
            String TestcaseDes;
            if (!TestCaseDesMap.containsKey(Key)) {
                TestcaseDes = "  ---------       ";
                TestCaseDesMap.put(Key, TestcaseDes);
                temp_key = Key;

            } else {
                TestcaseDes = TestCaseDesMap.get(Key);
                temp_key = Key;
                // TestcaseStatusMap.put(Key, Status);
            }
            td.text(TestcaseDes);
            // Replace with your text
        }
    }

    Elements ths = report.select("table[id=tableStyle] th"); // select the tds from your table
    for (Element th : ths) { // loop through them

        if (th.text().contains("Method Type")) { // found the one you want
            th.text("TestCase Description");

        }
        if (th.text().contains("Test Case Name")) { // found the one you want
            th.text("Testng Method");

        }
    }

    if (!source.canWrite()) {
        System.out.println("Can't write this file!");//Just check if the file is writable or not
    }
    BufferedWriter bw = new BufferedWriter(new FileWriter(source));
    bw.write(dom.toString()); //toString will give all the elements as a big string
    bw.close(); //Close to apply the changes
    //  genarateFailureReport(new File("C:\\Users\\yanamalp\\Desktop\\Gen_jelly\\HTML_Design_Files\\CSS\\HtmlReport.html"), "c:\\");

}

From source file:com.weavers.duqhan.business.impl.ProductServiceImpl.java

@Override
public void loadTempProducts(List<StatusBean> statusBeans) {
    boolean isSuccess = true;
    String startDate = new Date().toString();
    Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE,
            "(==I==)DATE: " + startDate + "Store product details in temp product table start.....");
    try {/*  w  ww  .j  av  a  2 s  . c o  m*/
        String status = "";
        for (StatusBean statusBean : statusBeans) {
            status = "Link duplicate";
            Temtproductlinklist temtproductlinklist = temtproductlinklistDao.loadById(statusBean.getId());
            if (temtproductlinklist != null && temtproductlinklist.getStatus() == 0) {
                Product testProduct = productDao.getProductByExternelLink(temtproductlinklist.getLink());
                if (testProduct == null) {
                    String value = "";
                    Elements detailMain;
                    Elements detailSub;
                    Elements specifics;
                    double votes = 0.0;
                    double stars = 0.0;
                    double feedback = 0.0;
                    String url = temtproductlinklist.getLink();
                    try {
                        testProduct = new Product();
                        Product savedTestProduct;

                        //=================== Random sleep START ===================//
                        //                            TimeUnit.SECONDS.sleep(30 + (int) (Math.random() * 100));
                        Random randomObj = new Random();
                        TimeUnit.SECONDS.sleep(randomObj.ints(30, 60).findFirst().getAsInt());
                        //=================== Random sleep END =====================//

                        Document doc = Jsoup.connect(url).get();
                        detailMain = doc.select("#j-detail-page");
                        if (!detailMain.isEmpty()) {

                            //=================== Criteria Block START==================//
                            detailMain = doc.select(".rantings-num");
                            if (!detailMain.isEmpty()) {
                                votes = Double.valueOf(detailMain.text().split(" votes")[0].split("\\(")[1]);
                            }
                            detailMain = doc.select(".percent-num");
                            if (!detailMain.isEmpty()) {
                                stars = Double.valueOf(detailMain.text());
                            }
                            detailMain = doc.select("ul.ui-tab-nav li[data-trigger='feedback'] a");
                            if (!detailMain.isEmpty()) {
                                feedback = Double.valueOf(detailMain.text().split("\\(")[1].split("\\)")[0]);
                            }
                            //=================== Criteria Block END==================//

                            if (votes > 10.0 && stars > 4.0 && feedback > 4.0) {
                                detailMain = doc.select(".detail-wrap .product-name");
                                testProduct.setName(detailMain
                                        .text());/*.substring(0, Math.min(detailMain.text().length(), 50))*/
                                detailMain = doc.select(".detail-wrap .product-name");
                                testProduct.setDescription(detailMain.text());
                                testProduct.setExternalLink(url);
                                testProduct.setVendorId(1l);//??????????????????????

                                //=================== Packaging block START==================//
                                Double weight = 1.0;
                                Double width = 1.0;
                                Double height = 1.0;
                                Double length = 1.0;
                                detailMain = doc.select(
                                        "div#j-product-desc div.pnl-packaging-main ul li.packaging-item");
                                for (Element element : detailMain) {
                                    String packagingTitle = element.select("span.packaging-title").text();
                                    String packagingDesc = element.select("span.packaging-des").text();
                                    if (packagingTitle.trim().equals("Package Weight:")) {
                                        String str = packagingDesc;
                                        str = str.replaceAll("[^.?0-9]+", " ");
                                        if (Arrays.asList(str.trim().split(" ")) != null) {
                                            if (!Arrays.asList(str.trim().split(" ")).isEmpty()) {
                                                try {
                                                    weight = Double.parseDouble(
                                                            Arrays.asList(str.trim().split(" ")).get(0));
                                                } catch (Exception e) {
                                                    weight = 1.0;
                                                }
                                            }
                                        }
                                        System.out.println("weight == " + weight);
                                    } else if (packagingTitle.trim().equals("Package Size:")) {
                                        String str = packagingDesc;
                                        str = str.replaceAll("[^.?0-9]+", " ");
                                        if (Arrays.asList(str.trim().split(" ")) != null) {
                                            if (!Arrays.asList(str.trim().split(" ")).isEmpty()) {
                                                try {
                                                    width = Double.parseDouble(
                                                            Arrays.asList(str.trim().split(" ")).get(0));
                                                    height = Double.parseDouble(
                                                            Arrays.asList(str.trim().split(" ")).get(1));
                                                    length = Double.parseDouble(
                                                            Arrays.asList(str.trim().split(" ")).get(2));
                                                } catch (Exception e) {
                                                    width = 1.0;
                                                    height = 1.0;
                                                    length = 1.0;
                                                }
                                            }
                                        }
                                        System.out.println("width == " + width);
                                        System.out.println("height == " + height);
                                        System.out.println("length == " + length);
                                    }
                                }
                                //=================== Packaging block END==================//

                                //=================== Category block START==================//
                                detailMain = doc.select("div.ui-breadcrumb div.container a");
                                Long productCategoryId = 0L;
                                String parentPath = "";
                                String thisCategory = detailMain.last().text().trim();
                                System.out.println("thisCategory == " + thisCategory);
                                Category parentCategory = new Category();
                                parentCategory.setId(0L);
                                parentCategory.setParentPath("");
                                for (Element element : detailMain) {
                                    String newCategory;
                                    newCategory = element.text().trim();
                                    System.out.println("newCategory======" + newCategory);
                                    if (newCategory.equals("Home") || newCategory.equals("All Categories")) {
                                    } else {
                                        Category category = categoryDao.getCategoryByName(newCategory);
                                        if (category != null) {
                                            if (category.getName().equals(thisCategory)) {
                                                productCategoryId = category.getId();
                                                parentPath = category.getParentPath();
                                            }
                                            parentCategory = category;
                                        } else {
                                            category = new Category();
                                            category.setId(null);
                                            category.setName(newCategory);
                                            category.setParentId(parentCategory.getId());
                                            category.setParentPath(parentCategory.getParentPath()
                                                    + parentCategory.getId() + "=");
                                            category.setQuantity(0);
                                            category.setImgUrl("-");
                                            category.setDisplayText(newCategory);
                                            Category category2 = categoryDao.save(category);
                                            if (category.getName().equals(thisCategory)) {
                                                productCategoryId = category2.getId();
                                                parentPath = category2.getParentPath();
                                            }
                                            parentCategory = category2;
                                        }
                                    }
                                }
                                //=================== Category block END==================//

                                //=============== Specifications block START==============//
                                detailMain = doc.select(".product-property-list .property-item");
                                String specifications = "";
                                for (Element element : detailMain) {
                                    specifications = specifications
                                            + element.select(".propery-title").get(0).text().replace(",", "/")
                                                    .replace(":", "-")
                                            + ":" + element.select(".propery-des").get(0).text()
                                                    .replace(",", "/").replace(":", "-")
                                            + ",";//TODO:, check
                                }
                                //=============== Specifications Block END==============//

                                //=============== Shipping Time Block START==============//
                                String shippingTime = "";
                                detailMain = doc.select(".shipping-days[data-role='delivery-days']");
                                System.out.println("value detailMain" + detailMain.toString());
                                shippingTime = detailMain.text();
                                //=============== Shipping Time Block END==============//

                                //=============== Shipping Cost Block START==============//
                                detailMain = doc.select(".logistics-cost");
                                value = detailMain.text();
                                if (!value.equalsIgnoreCase("Free Shipping")) {
                                    //                                        f = 0.00;
                                } else {
                                    //                                        f = Double.parseDouble(value.replaceAll(".*?([\\d.]+).*", "$1"));
                                }
                                //=============== Shipping Cost Block END==============//

                                //=================Product save 1st START==============//
                                testProduct.setCategoryId(productCategoryId);
                                testProduct.setLastUpdate(new Date());
                                testProduct.setParentPath(parentPath);
                                testProduct.setImgurl("-");
                                testProduct.setProperties("-");
                                testProduct.setProductWidth(width);
                                testProduct.setProductLength(length);
                                testProduct.setProductWeight(weight);
                                testProduct.setProductHeight(height);
                                testProduct.setShippingRate(0.0);
                                testProduct.setShippingTime("45");
                                testProduct.setSpecifications(specifications);
                                savedTestProduct = productDao.save(testProduct);
                                //====================Product save 1st END==============//

                                //========= Property, Property Value, Property Product Map Block START ========//
                                double discountPrice = 0.0;
                                double actualPrice = 0.0;
                                double markupPrice = 0.0;
                                String id = "";
                                String allProperties = "";
                                //------------------------Read Color css START---------------------//
                                specifics = doc.select("#j-product-info-sku dl.p-property-item");
                                Elements cssdetailMain = doc.select("link[href]");
                                Document cssdoc = new Document("");
                                System.out.println(
                                        "====================================================cssdetailMain"
                                                + cssdetailMain.size());
                                for (Element element : cssdetailMain) {
                                    String cssurl = element.attr("abs:href");
                                    if (cssurl.contains("??main-detail")) {
                                        try {
                                            cssdoc = Jsoup.connect(cssurl).get();
                                        } catch (IOException ex) {

                                        }
                                        break;
                                    }
                                }
                                //-----------------------Read Color css END--------------------------//

                                //-----------Product Property, Property Value START--------//
                                Map<String, ProductPropertyvalues> propertyValuesMap = new HashMap<>();
                                if (!specifics.isEmpty()) {
                                    ProductProperties testPorperties;
                                    ProductProperties saveTestPorperties;
                                    ProductPropertyvalues testPropertyValues;
                                    for (Element specific : specifics) {
                                        System.out.println("head  ==== " + specific.select("dt").text());
                                        testPorperties = productPropertiesDao
                                                .loadByName(specific.select("dt").text());
                                        if (testPorperties == null) {
                                            testPorperties = new ProductProperties();
                                            testPorperties.setPropertyName(specific.select("dt").text());
                                            saveTestPorperties = productPropertiesDao.save(testPorperties);
                                        } else {
                                            saveTestPorperties = testPorperties;
                                        }
                                        allProperties = allProperties + saveTestPorperties.getId().toString()
                                                + "-";
                                        detailSub = specific.select("dd ul li");
                                        String valu = "-";
                                        for (Element element : detailSub) {
                                            testPropertyValues = new ProductPropertyvalues();
                                            id = element.select("a[data-sku-id]").attr("data-sku-id").trim();
                                            testPropertyValues.setRefId(id);
                                            if (element.hasClass("item-sku-image")) {
                                                valu = element.select("a img[src]").get(0).absUrl("src")
                                                        .split(".jpg")[0] + ".jpg";
                                                String title = element.select("a img").get(0).attr("title");
                                                String imgUrl = GoogleBucketFileUploader
                                                        .uploadProductImage(valu, savedTestProduct.getId());
                                                valu = "<img src='" + imgUrl + "' title='" + title
                                                        + "' style='height:40px; width:40px;'/>";
                                            } else if (element.hasClass("item-sku-color")) {
                                                String style = cssdoc.html().split("sku-color-" + id)[1]
                                                        .split("}")[0].substring(1);
                                                valu = "<span style='" + style
                                                        + "' ; height:40px; width:40px; display:block;'></span>";
                                            } else {
                                                valu = element.select("a span").toString();
                                            }
                                            System.out.println("valu === " + valu);
                                            testPropertyValues.setProductId(savedTestProduct.getId());
                                            testPropertyValues.setPropertyId(saveTestPorperties.getId());
                                            testPropertyValues.setValueName(valu);
                                            propertyValuesMap.put(id,
                                                    productPropertyvaluesDao.save(testPropertyValues));
                                        }
                                    }
                                    savedTestProduct.setProperties(allProperties);
                                }
                                //-----------Product Property, Property Value END--------//

                                //----------------------Read json START------------------//
                                List<AxpProductDto> axpProductDtos = new ArrayList<>();
                                Elements scripts = doc.select("script"); // Get the script part
                                for (Element script : scripts) {
                                    if (script.html().contains("var skuProducts=")) {
                                        String jsonData = "";
                                        jsonData = script.html().split("var skuProducts=")[1]
                                                .split("var GaData")[0].trim();
                                        jsonData = jsonData.substring(0, jsonData.length() - 1);
                                        Gson gsonObj = new Gson();
                                        axpProductDtos = Arrays
                                                .asList(gsonObj.fromJson(jsonData, AxpProductDto[].class));
                                        break;
                                    }
                                }
                                //----------------------Read json END------------------//

                                //-------------Product Properties Map START------------//
                                for (AxpProductDto thisAxpProductDto : axpProductDtos) {
                                    SkuVal skuVal = thisAxpProductDto.getSkuVal();
                                    if (skuVal.getActSkuCalPrice() != null) {
                                        value = skuVal.getActSkuCalPrice().trim();
                                        discountPrice = CurrencyConverter.usdTOinr(
                                                Double.parseDouble(value.replaceAll(".*?([\\d.]+).*", "$1")));
                                        value = skuVal.getSkuCalPrice().trim();
                                        actualPrice = CurrencyConverter.usdTOinr(
                                                Double.parseDouble(value.replaceAll(".*?([\\d.]+).*", "$1")));
                                        markupPrice = discountPrice * 0.15 + 100;
                                        discountPrice = Math.ceil((discountPrice + markupPrice) / 10) * 10;
                                        actualPrice = Math.round(actualPrice + markupPrice);
                                    } else {
                                        discountPrice = 0.0;
                                        value = skuVal.getSkuCalPrice().trim();
                                        actualPrice = CurrencyConverter.usdTOinr(
                                                Double.parseDouble(value.replaceAll(".*?([\\d.]+).*", "$1")));
                                        markupPrice = actualPrice * 0.15 + 100;
                                        discountPrice = Math.round(actualPrice + markupPrice);
                                        actualPrice = Math.round(actualPrice + markupPrice);
                                    }

                                    ProductPropertiesMap productPropertyMap = new ProductPropertiesMap();
                                    String myPropValueIds = "";
                                    if (thisAxpProductDto.getSkuAttr() != null) {
                                        String[] skuPropIds = thisAxpProductDto.getSkuPropIds().split(",");
                                        for (String skuPropId : skuPropIds) {
                                            myPropValueIds = myPropValueIds
                                                    + propertyValuesMap.get(skuPropId).getId().toString() + "_";
                                        }

                                        productPropertyMap.setPropertyvalueComposition(myPropValueIds);
                                    } else {
                                        productPropertyMap.setPropertyvalueComposition("_");
                                    }
                                    productPropertyMap.setDiscount(discountPrice);
                                    productPropertyMap.setPrice(actualPrice);
                                    productPropertyMap.setProductId(savedTestProduct);
                                    productPropertyMap.setQuantity(5l);
                                    productPropertiesMapDao.save(productPropertyMap);
                                }
                                //-------------Product Properties Map START------------//
                                //========= Property, Property Value, Property Product Map Block END ========//

                                //============= Multiple Image Block START =============//
                                detailMain = doc.select("ul.image-thumb-list span.img-thumb-item img[src]");
                                int flg = 0;
                                String imgUrl = "";
                                for (Element element : detailMain) {
                                    imgUrl = GoogleBucketFileUploader.uploadProductImage(
                                            element.absUrl("src").split(".jpg")[0] + ".jpg",
                                            savedTestProduct.getId());
                                    if (flg == 0) {
                                        flg++;
                                        savedTestProduct.setImgurl(imgUrl);
                                    } else {
                                        ProductImg productImg = new ProductImg();
                                        productImg.setId(null);
                                        productImg.setImgUrl(imgUrl);
                                        productImg.setProductId(savedTestProduct.getId());
                                        productImgDao.save(productImg);
                                    }
                                }
                                //============= Multiple Image Block END =============//

                                //=================Product save final START==============//
                                if (productDao.save(savedTestProduct) != null) {
                                    temtproductlinklist.setStatus(1);//
                                    temtproductlinklistDao.save(temtproductlinklist);
                                    status = "Success";
                                }
                                //=================Product save final START==============//
                            } else {
                                temtproductlinklist.setStatus(2);//
                                temtproductlinklistDao.save(temtproductlinklist);
                                status = "criteria mismatch";
                            }
                        } else {
                            status = "Page not found";
                        }
                    } catch (Exception ex) {
                        System.out.println(
                                "=============================================================Exception1" + ex);
                        temtproductlinklist.setStatus(4);//
                        temtproductlinklistDao.save(temtproductlinklist);
                        System.out.println("Exception === " + ex);
                        status = "Failure";
                        Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE, "(==E==)DATE: "
                                + new Date().toString()
                                + "Store product details in temp product table get error in sub process.....\n Link Id: "
                                + statusBean.getId() + "\n Started on" + startDate, ex);
                    }
                } else {
                    temtproductlinklist.setStatus(3);//
                    temtproductlinklistDao.save(temtproductlinklist);
                    status = "Product exsist";
                }
            }
            //                String body = "Id: " + temtproductlinklist.getId() + "<br/> Status: " + status;
            //                MailSender.sendEmail("krisanu.nandi@pkweb.in", "Product captured", body, "subhendu.sett@pkweb.in");
            statusBean.setStatus(status);
        }
        System.out.println("=============================================================status" + status);
    } catch (Exception e) {
        System.out.println("=============================================================Exception2" + e);
        isSuccess = false;
        String body = "(==E==)DATE: " + new Date().toString()
                + "Store product details in temp product table get error.....<br/> Started on" + startDate
                + "<br/>";
        Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE, body, e);
        //            MailSender.sendEmail("krisanu.nandi@pkweb.in", "Stopped store product details", body + e.getLocalizedMessage(), "subhendu.sett@pkweb.in");
    }
    if (isSuccess) {
        String body = "(==I==)DATE: " + new Date().toString()
                + "Store product details in temp product table end.....<br/> Started on" + startDate;
        Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE, body);
        /*ObjectMapper mapper = new ObjectMapper();
        try {
        MailSender.sendEmail("krisanu.nandi@pkweb.in", "Completed store product details", body + "=============<br/><br/>" + mapper.writeValueAsString(statusBeans), "subhendu.sett@pkweb.in");
        } catch (JsonProcessingException ex) {
        Logger.getLogger(ProductServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }*/
    }
    //        return statusBeans;
    System.out.println("=============================================================end");
}

From source file:com.github.irshulx.Components.InputExtensions.java

public void insertLink(String uri) {
    EditorType editorType = editorCore.getControlType(editorCore.getActiveView());
    EditText editText = (EditText) editorCore.getActiveView();
    if (editorType == EditorType.INPUT || editorType == EditorType.UL_LI) {
        String text = Html.toHtml(editText.getText());
        if (TextUtils.isEmpty(text))
            text = "<p dir=\"ltr\"></p>";
        text = trimLineEnding(text);/*  w  ww . j a  v a  2  s. co m*/
        Document _doc = Jsoup.parse(text);
        Elements x = _doc.select("p");
        String existing = x.get(0).html();
        x.get(0).html(existing + " <a href='" + uri + "'>" + uri + "</a>");
        Spanned toTrim = Html.fromHtml(x.toString());
        CharSequence trimmed = noTrailingwhiteLines(toTrim);
        editText.setText(trimmed); //
        editText.setSelection(editText.getText().length());
    }
}

From source file:com.licubeclub.zionhs.MainActivity.java

void networkTask() {
    SRL.setRefreshing(true);/*from  w w w .j a  v  a2 s  .  com*/
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
        }
    };

    final Handler mHandler = new Handler();
    new Thread() {

        public void run() {
            mHandler.post(new Runnable() {

                public void run() {
                    // SRL.setRefreshing(true);
                }
            });
            try {
                lunchstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "2"); //Get Lunch Menu Date
                dinnerstring = MealLoadHelper.getMeal("goe.go.kr", "J100000659", "4", "04", "3"); //Get Dinner Menu Date
            } catch (Exception e) {
            }

            try {
                int skipcount = 0;
                boolean skipped = false;
                schedulearray = new ArrayList<String>();
                dayarray = new ArrayList<String>();

                //                    ? ?? ? ??  
                Document doc = Jsoup.connect(URL).get();

                Elements rawdaydata = doc.select(".listDay"); //Get contents from the class,"listDay"
                for (Element el : rawdaydata) {
                    String daydata = el.text();
                    if (daydata.equals("") | daydata == null) {
                        if (skipped) {
                        } else {
                            skipcount++;
                        }
                    } else {
                        dayarray.add(daydata); // add value to ArrayList
                        skipped = true;
                    }
                }
                Log.d("Schedule", "Parsed Day Array" + dayarray);

                Elements rawscheduledata = doc.select(".listData"); //Get contents from tags,"a" which are in the class,"ellipsis"
                for (Element el : rawscheduledata) {
                    String scheduledata = el.text();
                    if (skipcount > 0) {
                        skipcount--;
                    } else {
                        schedulearray.add(scheduledata); // add value to ArrayList
                    }
                }
                Log.d("Schedule", "Parsed Schedule Array" + schedulearray);
                //                    SRL.setRefreshing(false);
            } catch (IOException e) {
                e.printStackTrace();
                //                    SRL.setRefreshing(false);

            }
            try {
                titlearray_np = new ArrayList<String>();
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=59")
                        .get();
                Elements rawdata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody"
                String titlestring = rawdata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                for (Element el : rawdata) {
                    String titledata = el.attr("title");
                    titlearray_np.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Array Strings" + titlearray_np);

            } catch (IOException e) {
                e.printStackTrace();

            }
            //Notices URL
            try {
                titlearray_n = new ArrayList<String>();
                // ? URL
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?" + "menugrp=110100&master=bbs&act=list&master_sid=58")
                        .get();
                //Get contents from tags,"a" which are in the class,"listbody"
                Elements rawmaindata = doc.select(".listbody a");
                String titlestring = rawmaindata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                // ??  ?
                for (Element el : rawmaindata) {
                    String titledata = el.attr("title");
                    titlearray_n.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Array Strings" + titlearray_n);

            } catch (IOException e) {
                e.printStackTrace();

            }

            mHandler.post(new Runnable() {
                public void run() {
                    //                        progressDialog.dismiss();
                    //                        SRL.setRefreshing(false);
                    if (AMorPM == Calendar.AM) {
                        MealString = lunchstring[DAYofWEEK - 1];
                    } else {
                        MealString = dinnerstring[DAYofWEEK - 1];
                    }
                    try {
                        ScheduleString = schedulearray.get(DAYofMONTH - 1);
                        NoticesParentString = titlearray_np.get(0);
                        NoticeString = titlearray_n.get(0);
                    } catch (Exception e) {
                        ScheduleString = getResources().getString(R.string.error);
                        NoticesParentString = getResources().getString(R.string.error);
                        NoticeString = getResources().getString(R.string.error);
                    }

                    if (MealString == null) {
                        MealString = getResources().getString(R.string.nodata);
                    } else if (MealString.equals("")) {
                        MealString = getResources().getString(R.string.nodata);
                    }
                    if (ScheduleString == null) {
                        ScheduleString = getResources().getString(R.string.nodata);
                    } else if (ScheduleString.equals("")) {
                        ScheduleString = getResources().getString(R.string.nodata);
                    }
                    SRL.setRefreshing(false);
                    handler.sendEmptyMessage(0);
                    setContentData();
                }
            });

        }
    }.start();

}

From source file:com.licubeclub.zionhs.Notices.java

private void networkTask() {
    NetworkChecker NetCheck = new NetworkChecker(Notices.this);
    if (NetCheck.isNetworkConnected()) {
        final Handler mHandler = new Handler();
        new Thread() {

            public void run() {

                mHandler.post(new Runnable() {

                    public void run() {
                        SRL.setRefreshing(true);
                    }//from   ww w .j  a va2  s . c om
                });

                //Task

                //Notices URL
                try {
                    titlearray = new ArrayList<String>();
                    titleherfarray = new ArrayList<String>();
                    authorarray = new ArrayList<String>();
                    datearray = new ArrayList<String>();
                    // ? URL
                    Document doc = Jsoup.connect(url).get();
                    Elements rawmaindata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody"
                    Elements rawauthordata = doc.select("td:eq(3)"); //? ?  - 3 td ? 
                    Elements rawdatedata = doc.select("td:eq(4)"); // ?  - 4 td ? 
                    String titlestring = rawmaindata.toString();
                    Log.i("Notices", "Parsed Strings" + titlestring);

                    // ??  ?
                    for (Element el : rawmaindata) {
                        String titlherfedata = el.attr("href");
                        String titledata = el.attr("title");
                        titleherfarray.add("http://www.zion.hs.kr/" + titlherfedata); // add value to ArrayList
                        titlearray.add(titledata); // add value to ArrayList
                    }
                    Log.i("Notices", "Parsed Link Array Strings" + titleherfarray);
                    Log.i("Notices", "Parsed Array Strings" + titlearray);

                    for (Element el : rawauthordata) {
                        String authordata = el.text();
                        Log.d("Author", el.text());
                        authorarray.add(authordata);
                    }
                    for (Element el : rawdatedata) {
                        String datedata = el.text();
                        Log.d("Date", el.text());
                        datearray.add(datedata);
                    }

                } catch (IOException e) {
                    e.printStackTrace();

                }

                mHandler.post(new Runnable() {
                    public void run() {
                        //UI Task
                        // ? 
                        adapter = new PostListAdapter(Notices.this, titlearray, datearray, authorarray);
                        listview.setAdapter(adapter);
                        listview.setOnItemClickListener(GoToWebPage);
                        handler.sendEmptyMessage(0);
                        SRL.setRefreshing(false);

                        Toast.makeText(getApplicationContext(), getResources().getString(R.string.recent),
                                Toast.LENGTH_LONG).show();
                    }
                });

            }
        }.start();
    } else {
        Toast.makeText(getApplicationContext(), getString(R.string.network_connection_warning),
                Toast.LENGTH_LONG).show();
    }

}

From source file:com.licubeclub.zionhs.Notices_Parents.java

private void networkTask() {
    final Handler mHandler = new Handler();
    new Thread() {

        public void run() {

            mHandler.post(new Runnable() {

                public void run() {
                    SRL.setRefreshing(true);
                }//w  w  w.j  a v a2  s. c o m
            });

            //Task

            //Notices URL
            try {
                titlearray = new ArrayList<String>();
                titleherfarray = new ArrayList<String>();
                authorarray = new ArrayList<String>();
                datearray = new ArrayList<String>();
                Document doc = Jsoup.connect(
                        "http://www.zion.hs.kr/main.php?menugrp=110100&master=bbs&act=list&master_sid=59")
                        .get();
                Elements rawdata = doc.select(".listbody a"); //Get contents from tags,"a" which are in the class,"listbody"
                Elements rawauthordata = doc.select("td:eq(3)"); //? ?  - 3 td ? 
                Elements rawdatedata = doc.select("td:eq(4)"); // ?  - 4 td ? 

                String titlestring = rawdata.toString();
                Log.i("Notices", "Parsed Strings" + titlestring);

                for (Element el : rawdata) {
                    String titlherfedata = el.attr("href");
                    String titledata = el.attr("title");
                    titleherfarray.add("http://www.zion.hs.kr/" + titlherfedata); // add value to ArrayList
                    titlearray.add(titledata); // add value to ArrayList
                }
                Log.i("Notices", "Parsed Link Array Strings" + titleherfarray);
                Log.i("Notices", "Parsed Array Strings" + titlearray);

                for (Element el : rawauthordata) {
                    String authordata = el.text();
                    Log.d("Author", el.text());
                    authorarray.add(authordata);
                }
                for (Element el : rawdatedata) {
                    String datedata = el.text();
                    Log.d("Date", el.text());
                    datearray.add(datedata);
                }

            } catch (IOException e) {
                e.printStackTrace();

            }

            mHandler.post(new Runnable() {
                public void run() {
                    //UI Task
                    adapter = new PostListAdapter(Notices_Parents.this, titlearray, datearray, authorarray);
                    listview.setAdapter(adapter);
                    listview.setOnItemClickListener(GoToWebPage);
                    handler.sendEmptyMessage(0);
                    SRL.setRefreshing(false);

                    Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.noti_parents_info),
                            Toast.LENGTH_LONG);
                    toast.setGravity(Gravity.TOP, 0, 0);
                    toast.show();
                }
            });

        }
    }.start();

}

From source file:org.aliuge.crawler.extractor.selector.AbstractElementCssSelector.java

/**
 * ????// w  ww .java  2s . com
 * @param elements
 * @return
 */
protected String getExtractText(Elements elements) {
    if (elements.size() == 0)
        return null;
    String temp = "";

    if (attr.equalsIgnoreCase("tostring")) {
        return temp = elements.toString();
    } else {
        if (index == -1 && StringUtils.isNotBlank(this.regex)) {
            for (Element e : elements) {
                Element element = e;
                if (element.select(this.regex).size() > 0) {
                    return temp = e.text();
                }
            }
            return temp;
        } else {
            if (index > -1 && index < elements.size()) {
                return elements.get(index).text();
            }
        }
        return elements.first().text();
    }

    /*if(attr.equals("tostring")){
       if(index==0 || index>elements.size())
    temp = elements.first().toString();
       else
    temp = elements.get(index).toString();
    }else{
       if(index==0 || index>elements.size())
    temp = elements.first().text();
       else
    temp = elements.get(index).text();
    }
            
    if(null!=pattern){
       Matcher m = pattern.matcher(temp);
       if(m.find()){
    temp = m.group(1);
       }
    }*/
    //return temp;
}

From source file:org.aliuge.crawler.extractor.selector.IntegerElementCssSelector.java

@Override
public Integer getContent() throws ExtractException {
    Elements elements = null;
    try {// w ww.j ava 2  s . c  o m
        // content???document2+??
        if (null != content && !newDoc) {
            return content;
        }
        if (null != document) {
            elements = super.document.select(value);
            if (elements.isEmpty())
                return null;
            String temp;
            switch ($Attr) {
            case text:
                temp = CharMatcher.DIGIT.retainFrom(getExtractText(elements));
                break;
            default:
                temp = CharMatcher.DIGIT.retainFrom(getExtractAttr(elements, attr));
                break;
            }

            if (StringUtils.isNotBlank(temp)) {
                Integer integer = Integer.parseInt(temp);
                this.content = integer;
                newDoc = false;
                return content;
            }
        }
    } catch (Exception e) {
        //e.printStackTrace();
        log.error(elements.toString());
        throw new ExtractException("????:" + e.getMessage());
    }
    return null;
}