當前位置: 首頁>>代碼示例>>Java>>正文


Java Element.remove方法代碼示例

本文整理匯總了Java中org.jsoup.nodes.Element.remove方法的典型用法代碼示例。如果您正苦於以下問題:Java Element.remove方法的具體用法?Java Element.remove怎麽用?Java Element.remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jsoup.nodes.Element的用法示例。


在下文中一共展示了Element.remove方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: process

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
@Override
public void process(final ExecutionContext executionContext, final Document document)
        throws ProcessException {
    try {
        Elements xkSections = document.getElementsByAttribute(XK_SECTION_ATTR);
        if (xkSections != null) {
            for (Element xkSectionTag : xkSections) {
                Element xkSectionStylesTag = xkSectionTag.getElementsByAttribute(XK_SECTION_STYLES_ATTR).first();
                if (xkSectionStylesTag != null) {
                    String xkSectionStyles = xkSectionStylesTag.attr(XK_SECTION_STYLES_ATTR);
                    xkSectionTag.addClass(xkSectionStyles.trim());
                    xkSectionStylesTag.remove();
                }
            }
        }
    } catch (Exception e) {
        throw new ProcessException(e);
    }
}
 
開發者ID:DantaFramework,項目名稱:AEM,代碼行數:20,代碼來源:XKSectionStylesDOMProcessor.java

示例2: removeUselessElements

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private static void removeUselessElements(Element element) {
    for (Element child : element.children()) {
        if (child.children().size() > 0)
            removeUselessElements(child);
        else {
            switch (child.tagName()) {
                case "br":
                case "a":
                case "p":
                case "h1":
                case "h2":
                case "h3":
                case "h4":
                case "span":
                    break;
                default:
                    Element parent = child.parent();
                    child.remove();
                    parent.insertChildren(0, child.children());
                    break;
            }
        }
    }
}
 
開發者ID:TheAndroidMaster,項目名稱:Blackboard,代碼行數:25,代碼來源:HtmlUtils.java

示例3: ifDevelopment

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private void ifDevelopment(Element element){

        String attrValue = element.attr(IF_DEV_ATTR);
        element.removeAttr(IF_DEV_ATTR);
        boolean keepElement = true;

        if(attrValue.equalsIgnoreCase("false"))
            keepElement = false;

        //Remove element if NOT in DEVELOPMENT_MODE
        if(keepElement&&!app.underDevelopment())
            element.remove();


        //Remove element if in DEVELOPMENT_MODE
        if(!keepElement&&app.underDevelopment())
            element.remove();

    }
 
開發者ID:Emerjoin,項目名稱:Hi-Framework,代碼行數:20,代碼來源:IfDevTrasformer.java

示例4: url2xhtml

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
/**
 * 將頁麵轉為{@link org.jsoup.nodes.Document}對象,xhtml 格式
 *
 * @param url
 * @return
 * @throws Exception
 */
protected Document url2xhtml(String url) throws Exception {
    Document doc = Jsoup.connect(url).get(); //獲得

    if (logger.isDebugEnabled()) {
        logger.debug("baseUri: {}", doc.baseUri());
    }

    for (Element script : doc.getElementsByTag("script")) { //除去所有 script
        script.remove();
    }

    for (Element a : doc.getElementsByTag("a")) { //除去 a 的 onclick,href 屬性
        a.removeAttr("onclick");
        a.removeAttr("href");
    }

    Elements links = doc.getElementsByTag("link"); //將link中的地址替換為絕對地址
    for (Element element : links) {
        String href = element.absUrl("href");

        if (logger.isDebugEnabled()) {
            logger.debug("href: {} -> {}", element.attr("href"), href);
        }

        element.attr("href", href);
    }

    doc.outputSettings()
            .syntax(Document.OutputSettings.Syntax.xml)
            .escapeMode(Entities.EscapeMode.xhtml);  //轉為 xhtml 格式

    if (logger.isDebugEnabled()) {
        String[] split = doc.html().split("\n");
        for (int c = 0; c < split.length; c++) {
            logger.debug("line {}:\t{}", c + 1, split[c]);
        }
    }
    return doc;
}
 
開發者ID:vindell,項目名稱:docx4j-template,代碼行數:47,代碼來源:HtmlConverter.java

示例5: removeNodesWithNegativeScores

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
/**
 * If there are elements inside our top node that have a negative gravity
 * score remove them
 */
private void removeNodesWithNegativeScores(Element topNode) {
    Elements gravityItems = topNode.select("*[gravityScore]");
    for (Element item : gravityItems) {
        int score = getScore(item);
        int paragraphIndex = getParagraphIndex(item);
        if (score < 0 || item.text().length() < getMinParagraph(paragraphIndex)) {
            item.remove();
        }
    }
}
 
開發者ID:XndroidDev,項目名稱:Xndroid,代碼行數:15,代碼來源:OutputFormatter.java

示例6: stripUnlikelyCandidates

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
/**
 * Removes unlikely candidates from HTML. Currently takes id and class name
 * and matches them against list of patterns
 *
 * @param doc document to strip unlikely candidates from
 */
protected void stripUnlikelyCandidates(Document doc) {
    for (Element child : doc.select("body").select("*")) {
        String className = child.className().toLowerCase();
        String id = child.id().toLowerCase();

        if (NEGATIVE.matcher(className).find()
                || NEGATIVE.matcher(id).find()) {
            child.remove();
        }
    }
}
 
開發者ID:XndroidDev,項目名稱:Xndroid,代碼行數:18,代碼來源:ArticleTextExtractor.java

示例7: getContent

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private String getContent() {
    Document doc = Jsoup.parse(getIntent("content"));
    Element imageElement = doc.select("img").first();
    if (imageElement != null) imageElement.remove();
    return "<div>" + doc.toString() + "</div>";
}
 
開發者ID:daeng-id,項目名稱:nfkita-mobile,代碼行數:7,代碼來源:ReadArticleActivity.java


注:本文中的org.jsoup.nodes.Element.remove方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。