当前位置: 首页>>代码示例>>Java>>正文


Java Element.childNodes方法代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:21,代码来源:OutputFormatter.java

示例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;
	}
 
开发者ID:handexing,项目名称:frameworkAggregate,代码行数:33,代码来源:MyJsoup.java

示例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());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
 
开发者ID:tranleduy2000,项目名称:ascii_generate,代码行数:34,代码来源:GetEmoticons.java

示例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();
}
 
开发者ID:fengzhizi715,项目名称:NetDiscovery,代码行数:11,代码来源:CssSelector.java

示例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();
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:36,代码来源:DebateHTMLParser.java

示例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();
}
 
开发者ID:xbynet,项目名称:crawler,代码行数:11,代码来源:JsoupParser.java


注:本文中的org.jsoup.nodes.Element.childNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。