本文整理匯總了Java中org.jsoup.nodes.Node.childNodes方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.childNodes方法的具體用法?Java Node.childNodes怎麽用?Java Node.childNodes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jsoup.nodes.Node
的用法示例。
在下文中一共展示了Node.childNodes方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getChildNodes
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected List<? extends Node> getChildNodes(final Node node, final String withName) {
if (node==null)
return Collections.EMPTY_LIST;
if (Selector.UNIVERSAL_TAG.equals(withName))
return filter(node.childNodes());
ArrayList<Node> result = new ArrayList<Node>();
List<Node> children = node.childNodes();
for(Node child : children)
if (nameMatches(child, withName))
result.add(child);
return result;
}
示例2: getCategoryList
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
private static List<FlowerCategory> getCategoryList() {
List<FlowerCategory> categories = new ArrayList<FlowerCategory>();
try {
Document doc = Jsoup.connect("http://www.aihuhua.com/baike/").get();
Elements catelist = doc.getElementsByClass("catelist");
Element cates = catelist.first();
List<Node> childNodes = cates.childNodes();
for (int i = 0; i < childNodes.size(); i++) {
Node node = childNodes.get(i);
List<Node> childs = node.childNodes();
if (childs != null && childs.size() > 0) {
FlowerCategory category = new FlowerCategory();
for (int j = 0; j < childs.size(); j++) {
Node child = childs.get(j);
if ("a".equals(child.nodeName())) {
category.setUrl(child.attr("href"));
category.setImgPath(child.childNode(1).attr("src"));
} else if ("h2".equals(child.nodeName())) {
category.setName(child.attr("title"));
}
}
categories.add(category);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return categories;
}
示例3: parseHTMLNodeToParagraphs
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
private static List<CodeInfo> parseHTMLNodeToParagraphs(Node node) {
List<CodeInfo> paragraphList = new ArrayList<>();
List<Node> childNodes = node.childNodes();
for (Node childNode : childNodes) {
if (childNode.nodeName().equals("p") || childNode.nodeName().equals("li")) continue;
if (childNode.nodeName().equals("pre"))
childNode.childNodes().stream()
.filter(n -> n.nodeName().equals("code"))
.map(n -> new CodeInfo(StringEscapeUtils.unescapeHtml4(((Element) n).text())))
.forEach(paragraphList::add);
else paragraphList.addAll(parseHTMLNodeToParagraphs(childNode));
}
return paragraphList;
}
示例4: extractElementsText
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
private String extractElementsText( Node element ) {
String textContent = "";
for( Node childElement : element.childNodes() ){
if( childElement instanceof TextNode ){
textContent += " " + ((TextNode) childElement).text();
}
if( childElement.childNodes().size() > 0 ){
textContent += " " + extractElementsText( childElement );
}
}
return textContent;
}
示例5: unwrapFirstNotBlankBlock
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
/**
* 將塊元素中的第一個非空白文本節點獨立成 body 的第一個節點。
*/
private static boolean unwrapFirstNotBlankBlock(Node node) {
List<Node> childNodes = node.childNodes();
for (Node child : childNodes) {
// 如果是文本節點,且節點內容為空白,則繼續遞歸,否則結束遞歸
if (child instanceof TextNode) {
TextNode tn = (TextNode) child;
if (StringUtils.isBlank(tn.text())) {
// tn.text("");
continue;
}
return true;
}
if (child instanceof Element) {
Element e = (Element) child;
// 如果節點不是塊元素,則結束遞歸
if (!e.isBlock() || e.hasAttr("class") || e.hasAttr("style")) {
return true;
}
// 將塊元素節點內的內容獨立出來,如果還有節點存在則繼續遞歸
Node firstChild = e.unwrap();
logger.debug("Unwraped block element: {}, firstChild: {}", e.nodeName(), (firstChild == null ? null
: firstChild.nodeName()));
if (firstChild == null || unwrapFirstNotBlankBlock(firstChild.parent())) {
return true;
}
}
}
return false;
}
示例6: getTransactions
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
public static List<Transaction> getTransactions(String html) {
List<Transaction> transactions = new ArrayList<Transaction>();
Document document = Jsoup.parse(html);
Elements elements = document.getElementsByClass("uneven");
for (Element element : elements) {
Transaction t = new Transaction();
int index = 0;
List<Node> nodes = element.childNodes();
for (Node node : nodes) {
List<Node> subNodes = node.childNodes();
for (Node subNode : subNodes) {
if (subNode instanceof TextNode) {
TextNode textNode = (TextNode) subNode;
if (index == 0) {
t.setDate(textNode.getWholeText());
} else if (index == 1) {
t.setType(textNode.getWholeText());
} else if (index == 2) {
t.setPrice(textNode.getWholeText());
} else if (index == 3) {
t.setPlace(textNode.getWholeText());
}
index++;
}
}
}
transactions.add(0, t);
}
return transactions;
}
示例7: getFullText
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
public static String getFullText(Node node) {
if (node.childNodes().size() == 0) {
return Jsoup.parse(node.toString()).text();
}
String result = "";
for (Node no : node.childNodes()) {
result +=getFullText(no) + " ";
}
return result.trim();
}
示例8: renderDialogScript
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
/**
* get the aem wrapper element
*
* @param path
* @param resourceType
* @return json string
*/
public String renderDialogScript(String path, String resourceType) {
String html = this._includeResource(path, resourceType, true);
Document document = Jsoup.parse(html);
EditDialog editDialog = null;
for (Node node : document.body().childNodes()) {
if (node instanceof Element) {
editDialog = parseEditDialog(node);
for (Node child : node.childNodes()) {
if (child instanceof Element) {
EditDialog childDialog = parseEditDialog(child);
editDialog.setChild(childDialog);
childDialog.setHtml(((Element) child).html());
break;
}
}
break;
}
}
if (editDialog == null) {
return "null";
}
try {
return mapper.writeValueAsString(editDialog);
} catch (JsonProcessingException e) {
LOG.error("cannot convert editdialog to json", e);
return "null";
}
}
示例9: iterate
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
private void iterate(final ExtractionContext context, final Node elem) {
for (Node node : elem.childNodes()) {
text(context, node);
}
}
示例10: traverse
import org.jsoup.nodes.Node; //導入方法依賴的package包/類
public void traverse(Node node) {
for (Node childNode : node.childNodes()) {
visitor.visit(childNode);
traverse(childNode);
}
}