本文整理汇总了Java中org.jsoup.nodes.Element.clone方法的典型用法代码示例。如果您正苦于以下问题:Java Element.clone方法的具体用法?Java Element.clone怎么用?Java Element.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Element
的用法示例。
在下文中一共展示了Element.clone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clean
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
protected String clean(Element element) {
Element work = element.clone();
String[] unwantedElements = "img,script,style,link,canvas".split(",");
String[] unwantedAttributes = "style,class,target,id,src".split(",");
for (String tag : unwantedElements) {
work.getElementsByTag(tag).forEach((el) -> {
el.remove();
});
}
for (String attr : unwantedAttributes) {
work.getElementsByAttribute(attr).forEach((el) -> {
el.removeAttr(attr);
});
}
return work.html().replaceAll("\\s{2,}", " ");
}
示例2: 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();
}
示例3: checkElementAndConvert
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
/**
* Only document can be select
* See: https://github.com/code4craft/webmagic/issues/113
*
* @param elementIterator elementIterator
* @return element element
*/
private Element checkElementAndConvert(ListIterator<Element> elementIterator) {
Element element = elementIterator.next();
if (!(element instanceof Document)) {
Document root = new Document(element.ownerDocument().baseUri());
Element clone = element.clone();
root.appendChild(clone);
elementIterator.set(root);
return root;
}
return element;
}