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


Java Element.removeAttr方法代碼示例

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


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

示例1: getUpdatedFileContent

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
private String getUpdatedFileContent(List<Vacancy> vacancies) {

        Document document = null;
        try {
            document = getDocument();

            Element templateOriginal = document.getElementsByClass("template").first();
            Element copyTemplate = templateOriginal.clone();
            copyTemplate.removeAttr("style");
            copyTemplate.removeClass("template");
            document.select("tr[class=vacancy]").remove().not("tr[class=vacancy template");

            for (Vacancy vacancy : vacancies) {
                Element localClone = copyTemplate.clone();
                localClone.getElementsByClass("city").first().text(vacancy.getCity());
                localClone.getElementsByClass("companyName").first().text(vacancy.getCompanyName());
                localClone.getElementsByClass("salary").first().text(vacancy.getSalary());
                Element link =localClone.getElementsByTag("a").first();
                link.text(vacancy.getTitle());
                link.attr("href", vacancy.getUrl());

                templateOriginal.before(localClone.outerHtml());
            }
        } catch (IOException e) {
            e.printStackTrace();
            return "Some exception occurred";
        }
        return document.html();
    }
 
開發者ID:avedensky,項目名稱:JavaRushTasks,代碼行數:30,代碼來源:HtmlView.java

示例2: 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

示例3: 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

示例4: removeUselessAttributes

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
public static void removeUselessAttributes(Element element) {
    for (Element child : element.getAllElements()) {
        if (child.hasAttr("style"))
            child.removeAttr("style");
    }
}
 
開發者ID:TheAndroidMaster,項目名稱:Blackboard,代碼行數:7,代碼來源:HtmlUtils.java

示例5: modifyBootstrapPage

import org.jsoup.nodes.Element; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void modifyBootstrapPage(final BootstrapPageResponse response) {

    response.getDocument().child(0).attr("lang", "de");

    final Element head = response.getDocument().head();

    head.getElementsByAttributeValueContaining("http-equiv", "X-UA-Compatible").remove();

    head.appendElement("meta").attr("name", "viewport").attr("content", "width=device-width, initial-scale=1, shrink-to-fit=no");
    head.appendElement("link").attr("rel", "stylesheet").attr("href", "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css");

    final Element body = response.getDocument().body();
    body.removeAttr("scroll");

    //     body.append("<script src=\"./VAADIN/themes/mytheme/js/jquery-3.2.1.slim.min.js\"</script>");
    // https://v4-alpha.getbootstrap.com/components/tooltips/
    //   body.append("<script src=\"./VAADIN/themes/mytheme/js/tether-1.4.0.js\"</script>");
    // body.append("<script src=\"./VAADIN/themes/mytheme/bootstrap/js/bootstrap.min.js\"</script>");
    //  body.append("<script src=\"" + contextPath + "/VAADIN/themes/map-bootstrap/vendor/bootstrap/js/bootstrap.min.js\"></script>");
    //  body.append("<script src=\"" + contextPath + "/VAADIN/themes/map-bootstrap/vendor/material-design/js/arrive.min.js\"></script>");
    //  body.append("<script src=\"" + contextPath + "/VAADIN/themes/map-bootstrap/vendor/material-design/js/material.min.js\"></script>");
    //  body.append("<script src=\"" + contextPath + "/VAADIN/themes/map-bootstrap/vendor/material-design/js/ripples.min.js\"></script>");
    //  body.append("<script>$.material.init();</script>");
    //  body.append("<div id=\"map-alerts\" class=\"sr-only\" aria-atomic=\"true\" aria-live=\"assertive\" role=\"alert\"></div>");
}
 
開發者ID:knoobie,項目名稱:bootstrap-formgroup,代碼行數:30,代碼來源:MySessionListener.java


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