當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。