本文整理汇总了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();
}
示例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();
}
示例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;
}
示例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");
}
}
示例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>");
}