本文整理汇总了Java中org.jsoup.nodes.Element.childNodes方法的典型用法代码示例。如果您正苦于以下问题:Java Element.childNodes方法的具体用法?Java Element.childNodes怎么用?Java Element.childNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Element
的用法示例。
在下文中一共展示了Element.childNodes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendTextSkipHidden
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private void appendTextSkipHidden(Element e, StringBuilder accum, int indent) {
for (Node child : e.childNodes()) {
if (unlikely(child)) {
continue;
}
if (child instanceof TextNode) {
TextNode textNode = (TextNode) child;
String txt = textNode.text();
accum.append(txt);
} else if (child instanceof Element) {
Element element = (Element) child;
if (accum.length() > 0 && element.isBlock()
&& !lastCharIsWhitespace(accum))
accum.append(' ');
else if (element.tagName().equals("br"))
accum.append(' ');
appendTextSkipHidden(element, accum, indent + 1);
}
}
}
示例2: getCategoryList
import org.jsoup.nodes.Element; //导入方法依赖的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: print2
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private void print2(String baseLocation) throws IOException, TransformerException, ParserConfigurationException {
Document document = Jsoup.connect(baseLocation).get();
Elements content = document.getElementsByAttributeValue("class", "entry-content");
String title = null;
ArrayList<String> list = new ArrayList<>();
for (Element div : content) {
List<Node> nodes = div.childNodes();
for (Node node : nodes) {
if (node instanceof Element) {
if (((Element) node).tagName().equals("h3")) {
writeFile(title, list);
list.clear();
System.out.println("Title: " + node.childNode(0));
title = node.childNode(0).toString();
} else if (((Element) node).tagName().equals("table")) {
//print table
Elements tr = ((Element) node).getElementsByTag("tr");
for (Element element : tr) {
Elements td = element.getElementsByTag("td");
for (Element value : td) {
if (value.childNodeSize() > 0) {
if (!(value.childNode(0) instanceof Comment)) {
// System.out.println("Emoticon: " + value.childNode(0) + " " + value.childNode(0).getClass().getSimpleName());
list.add(value.childNode(0).toString());
}
}
}
}
}
}
}
}
}
示例4: getText
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
protected String getText(Element element) {
StringBuilder accum = new StringBuilder();
for (Node node : element.childNodes()) {
if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
accum.append(textNode.text());
}
}
return accum.toString();
}
示例5: paragraphElementToString
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
/**
* Extracts elements from the html comments (paragraph breaks, links)
*
* @param pElement paragraph element
* @return plain text
*/
public static String paragraphElementToString(Element pElement)
{
StringBuilder sb = new StringBuilder();
for (Node child : pElement.childNodes()) {
if (child instanceof TextNode) {
TextNode textNode = (TextNode) child;
sb.append(textNode.text());
}
else if (child instanceof Element) {
Element element = (Element) child;
// append new line for break
if ("br".equals(element.tag().getName())) {
sb.append("\n");
}
else if ("a".equals(element.tag().getName())) {
// extract link from a.href
sb.append(" ").append(element.attr("href")).append(" ");
}
else {
// or just add the text
sb.append(" ").append(element.text()).append(" ");
}
}
}
return sb.toString();
}
示例6: getText
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
protected String getText(Element element) {
StringBuilder accum = new StringBuilder();
for (Node node : element.childNodes()) {
if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
accum.append(textNode.text());
}
}
return accum.toString();
}