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