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