Example usage for org.jsoup.nodes Element children

List of usage examples for org.jsoup.nodes Element children

Introduction

In this page you can find the example usage for org.jsoup.nodes Element children.

Prototype

public Elements children() 

Source Link

Document

Get this element's child elements.

Usage

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void parseBulletedLists(Elements itms) {
    String bld = "";
    for (Element itm : itms) {
        Elements str = itm.getElementsByTag("li");
        for (Element itm2 : str) {
            if (itm2.children().size() >= 1) {
                Elements ch = itm2.getElementsByTag("a");
                for (Element c : ch) {
                    if (c.attr("href").contains("#"))
                        c.removeAttr("href");
                }//from  ww w.j a va 2 s  .c o  m
            }
            bld += ("\u2022 " + itm2.outerHtml() + "<br />");
        }
    }
    addText(bld, true, Typeface.DEFAULT);
}

From source file:im.ene.lab.attiq.ui.activities.ProfileActivity.java

@SuppressWarnings("unused")
public void onEventMainThread(DocumentEvent event) {
    if (event.document != null) {
        Elements stats = event.document.getElementsByClass("userActivityChart_stats");
        Element statBlock;
        if (!UIUtil.isEmpty(stats) && (statBlock = stats.first()) != null) {
            Elements statElements = statBlock.children();
            Integer contribution = null;
            for (Element element : statElements) {
                String unit = element.getElementsByClass("userActivityChart_statUnit").text();
                if ("Contribution".equals(unit.trim())) {
                    try {
                        contribution = Integer
                                .valueOf(element.getElementsByClass("userActivityChart_statCount").text());
                    } catch (NumberFormatException er) {
                        er.printStackTrace();
                    }/*from  w w  w  .  j ava  2 s .co m*/

                    break;
                }
            }

            if (contribution != null) {
                ((State) mState).contribution = contribution;
                EventBus.getDefault().post(new StateEvent<>(getClass().getSimpleName(), true, null, mState));
            }
        }
    }
}

From source file:org.aliuge.crawler.extractor.selector.factory.ElementCssSelectorFactory.java

/**
 * <b>Element??Element??select//from w  ww  .ja  v  a2 s. c om
 * @param element
 * @return
 */
@SuppressWarnings("unchecked")
public static AbstractElementCssSelector create(Element element) {
    String name = element.attr("name");
    String value = element.attr("value");
    String type = element.attr("type");

    String attr = element.attr("attr");
    String pattern = element.attr("pattern");
    String regex = element.attr("regex");
    String required = element.attr("required");
    String sIndex = element.attr("index");
    boolean isRequired = false;
    if (StringUtils.isNotBlank(required)) {
        isRequired = Boolean.parseBoolean(required);
    }
    int index = -1;
    if (StringUtils.isNotBlank(sIndex)) {
        index = Integer.parseInt(sIndex) - 1;
    }
    AbstractElementCssSelector selector = ElementCssSelectorFactory.create(name, type, value, attr, isRequired,
            index, regex, pattern);
    // ?
    Elements children = element.children();
    for (Element e : children) {
        if ("action".equals(e.tagName())) {
            SelectorAction action = ActionFactory.create(e, element.attr("type"));
            if (action != null)
                selector.addAction(action);
        }
        // ?Url
        else if ("element".equals(e.tagName())) {
            ((PageElementSelector) selector).addSelector(create(e));
        }
    }
    return selector;
}

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

/**
 * ?<b>elementIf?</br>//  w  w  w .ja  v  a 2 s  .  com
 * ??
 * @param document
 * @return
 */
public static IFConditions create(Element element) {
    if (element != null) {
        String exp = element.attr("test");
        IFConditions iFconditions = new IFConditions(exp);
        Elements selectElements = element.children();
        for (Element e : selectElements) {
            if (e.tagName().equals("element")) {
                iFconditions.addSelector(ElementCssSelectorFactory.create(e));
            }
        }
        return iFconditions;
    }
    return null;
}

From source file:org.apdplat.superword.extract.ChineseSynonymAntonymExtractor.java

public static SynonymAntonym parseSynonymAntonym(String html, String word) {
    SynonymAntonym synonymAntonym = new SynonymAntonym();
    synonymAntonym.setWord(new Word(word, ""));
    try {//from www .  j  a  v a 2s  . c  o m
        for (Element element : Jsoup.parse(html).select(SYNONYM_ANTONYM_CSS_PATH)) {
            int size = element.children().size();
            LOGGER.debug("element size:" + size);
            for (int i = 0; i < size / 2; i++) {
                String type = element.child(i * 2).text();
                LOGGER.debug("type:" + type);
                if ("??".equals(type)) {
                    String synonym = element.child(i * 2 + 1).text();
                    LOGGER.debug("synonym:" + synonym);
                    for (String w : synonym.split("\\s+")) {
                        w = w.replaceAll("\\s+", "");
                        if (w.length() < 2) {
                            continue;
                        }
                        if (isNotChineseChar(w)) {
                            LOGGER.debug("?" + w);
                            continue;
                        }
                        if (w.equals(word)) {
                            continue;
                        }
                        LOGGER.debug("word:" + w);
                        synonymAntonym.addSynonym(new Word(w, ""));
                    }
                }
                if ("???".equals(type)) {
                    String antonym = element.child(i * 2 + 1).text();
                    LOGGER.debug("antonym:" + antonym);
                    for (String w : antonym.split("\\s+")) {
                        w = w.replaceAll("\\s+", "");
                        if (w.length() < 2) {
                            continue;
                        }
                        if (isNotChineseChar(w)) {
                            LOGGER.debug("?" + w);
                            continue;
                        }
                        LOGGER.debug("word:" + w);
                        synonymAntonym.addAntonym(new Word(w, ""));
                    }
                }
            }
        }
        if (!synonymAntonym.getAntonym().isEmpty() || !synonymAntonym.getSynonym().isEmpty()) {
            LOGGER.info("??????" + synonymAntonym);
        }
    } catch (Exception e) {
        LOGGER.error("??????", e);
    }
    return synonymAntonym;
}

From source file:org.apdplat.superword.tools.ProxyIp.java

private static String getIps(Element element) {
    StringBuilder ip = new StringBuilder();
    Elements all = element.children();
    LOGGER.info("");
    LOGGER.info("?IP?" + element.text());
    AtomicInteger count = new AtomicInteger();
    all.forEach(ele -> {/*from  w  w  w.  j  a va 2s  .com*/
        String html = ele.outerHtml();
        LOGGER.info(count.incrementAndGet() + "?" + "HTML" + html.replaceAll("[\n\r]", ""));
        String text = ele.text();
        if (ele.hasAttr("style")
                && (ele.attr("style").equals("display: none;") || ele.attr("style").equals("display:none;"))) {
            LOGGER.info("?" + text);
        } else {
            if (StringUtils.isNotBlank(text)) {
                LOGGER.info("?" + text);
                ip.append(text);
            } else {
                LOGGER.info("");
            }
        }
    });
    LOGGER.info("----------------------------------------------------------------");
    LOGGER.info("?ip: " + ip);
    LOGGER.info("----------------------------------------------------------------");
    Matcher matcher = IP_PATTERN.matcher(ip.toString());
    if (matcher.find()) {
        String _ip = matcher.group();
        LOGGER.info("ip??" + _ip);
        return _ip;
    } else {
        LOGGER.info("ip??" + ip);
    }
    return null;
}

From source file:org.arb.extractor.DomTreeWalker.java

private void collectIdsOnElement(Element element, AbstractCodeUnit codeUnit) {
    if (element.hasAttr("id")) {
        elementIdSet.add(element.attr("id"));
    }/*from  w ww  .ja v  a 2s.c om*/
    if (element.hasAttr("arb:id")) {
        arbIdSet.add(element.attr("arb:id"));
    }
    for (int i = 0; i < element.children().size(); i++) {
        collectIdsOnElement(element.child(i), codeUnit);
    }
}

From source file:org.arb.extractor.DomTreeWalker.java

/**
 * Extract resource from an element and all its children.
 *  /*w  w w. j a v a  2  s.  c o  m*/
 * @param element the target element.
 * @param codeUnit used to record all found replacement.
 */
private void extractResourceOnElement(Element element, AbstractCodeUnit codeUnit) {
    String ownText = element.ownText();
    if (!ownText.isEmpty() && !hasResource(element)) {
        DomCodeReplacement replacement = new DomCodeReplacement();
        replacement.setElement(element);
        replacement.setResourceText(ownText);
        replacement.setResourceId(getElementResourceId(element));
        if (replacement.getResourceId() == null) {
            replacement.setNewId(true);
            replacement.setUseArbId(true);
        }
        codeUnit.addReplacement(replacement);
    }
    for (int i = 0; i < element.children().size(); i++) {
        extractResourceOnElement(element.child(i), codeUnit);
    }
}

From source file:org.asqatasun.processing.ProcessRemarkServiceImpl.java

/**
 * // www  .j a v  a  2 s. c  o  m
 * @param element
 * @return 
 */
public String getSnippetFromElement(Element element) {
    String elementHtml = StringEscapeUtils.escapeHtml4(StringUtil.normaliseWhitespace(element.outerHtml()))
            .trim();
    if (element.children().isEmpty() || elementHtml.length() <= SNIPPET_MAX_LENGTH) {
        return elementHtml;
    }
    return properlyCloseSnippet(element, elementHtml, elementHtml.substring(0, SNIPPET_MAX_LENGTH));
}

From source file:org.asqatasun.rules.accessiweb22.Aw22Rule11013.java

/**
 * This methods checks whether the value of the for attribute of a label
 * node corresponds to the value of the id attribute of any child form field.
 * /*from   w w  w . ja  v a  2s . c  o m*/
 * @param childNodes
 * @param forAttributeValue
 * @return
 */
private boolean isForAttributeOfLabelEqualsToIdAttributeOfFormField(Element element, String forAttributeValue) {
    if (StringUtils.isBlank(forAttributeValue)) {
        return false;
    }
    for (Element el : element.children().select(FORM_ELEMENT_CSS_LIKE_QUERY)) {
        if (StringUtils.equalsIgnoreCase(forAttributeValue, el.id())) {
            return true;
        }
    }
    return false;
}