本文整理匯總了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;
}