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


Java TextNode类代码示例

本文整理汇总了Java中org.jsoup.nodes.TextNode的典型用法代码示例。如果您正苦于以下问题:Java TextNode类的具体用法?Java TextNode怎么用?Java TextNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TextNode类属于org.jsoup.nodes包,在下文中一共展示了TextNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseCollectionsRepositoryData

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
private Repository parseCollectionsRepositoryData(Element element) throws Exception{
    String fullName = element.select("div > div > a").attr("href");
    String owner = fullName.substring(1, fullName.lastIndexOf("/"));
    String repoName = fullName.substring(fullName.lastIndexOf("/") + 1);
    String ownerAvatar = element.select("div > div > a > img").attr("src");

    Elements articleElements = element.getElementsByTag("div");
    Element descElement = articleElements.get(articleElements.size() - 2);
    StringBuilder desc = new StringBuilder("");
    for(TextNode textNode : descElement.textNodes()){
        desc.append(textNode.getWholeText());
    }

    Element numElement = articleElements.last();
    String starNumStr =  numElement.select("a").get(0).textNodes().get(1).toString();
    String forkNumStr =  numElement.select("a").get(1).textNodes().get(1).toString();
    String language = "";
    Elements languageElements = numElement.select("span > span");
    if(languageElements.size() > 0){
        language = numElement.select("span > span").get(1).textNodes().get(0).toString();
    }

    Repository repo = new Repository();
    repo.setFullName(fullName);
    repo.setName(repoName);
    User user = new User();
    user.setLogin(owner);
    user.setAvatarUrl(ownerAvatar);
    repo.setOwner(user);

    repo.setDescription(desc.toString());
    repo.setStargazersCount(Integer.parseInt(starNumStr.replaceAll(" ", "")));
    repo.setForksCount(Integer.parseInt(forkNumStr.replaceAll(" ", "")));
    repo.setLanguage(language);

    return repo;
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:38,代码来源:RepositoriesPresenter.java

示例2: head

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
@Override
public void head(Node node, int depth) {
	String name = node.nodeName();
	if (node instanceof TextNode) {
		append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
	} else if (name.equals("ul")) {
		listNesting++;
	} else if (name.equals("li")) {
		append("\n ");
		for (int i = 1; i < listNesting; i++) {
			append("  ");
		}
		if (listNesting == 1) {
			append("* ");
		} else {
			append("- ");
		}
	} else if (name.equals("dt")) {
		append("  ");
	} else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr")) {
		append("\n");
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:HtmlToPlainText.java

示例3: gatherWuBi

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
private String gatherWuBi(Element tagContentEL) {
	Elements spans = tagContentEL.select("span.diczx7");
	for (Element span : spans) {
		if (span.text().equals("五笔:")) {
			// 后一个兄弟文本节点
			Node textNode = span.nextSibling();
			if (textNode instanceof TextNode) {
				String wubi=((TextNode) textNode).text();
				//去掉特殊字符
				wubi=wubi.replaceAll("\\W", "");
				return wubi;
			}
		}
	}
	return null;
}
 
开发者ID:yizhuoyan,项目名称:case-html-data-gather,代码行数:17,代码来源:HTMLDataGather.java

示例4: getResourceArrayMap

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
protected Map<String, List<String>> getResourceArrayMap(String tag) {
    Map<String, List<String>> map = new HashMap<>();

    Document document = getValuesXmlDocument();
    Elements elements = document.getElementsByTag(tag);

    for (Element element : elements) {
        Elements items = element.getElementsByTag("item");

        List<String> itemsText = new ArrayList<>();

        for (Element item : items) {
            String text = ((TextNode) item.childNode(0)).text();

            itemsText.add(text);
        }

        String name = element.attr("name");
        map.put(name, itemsText);
    }
    return map;
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:23,代码来源:ShadowResources.java

示例5: getStringResNameAndValueMap

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
/**
 * 获取strings.xml 资源名-值 映射表
 *
 * @return
 */
protected Map<String, String> getStringResNameAndValueMap() {
    Map<String, String> map = new HashMap<>();

    Document document = getValuesXmlDocument();
    Elements strings  = document.getElementsByTag("string");

    for (int i = 0; i < strings.size(); i++) {
        Element element = strings.get(i);
        String  name    = element.attr("name");

        if (element.childNodeSize() > 0 && element.childNode(0) instanceof TextNode) {
            String text = ((TextNode) element.childNode(0)).text();

            map.put(name, text);
        }
    }

    return map;
}
 
开发者ID:kkmike999,项目名称:YuiHatano,代码行数:25,代码来源:ShadowResources.java

示例6: appendTextSkipHidden

import org.jsoup.nodes.TextNode; //导入依赖的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

示例7: mapAllElements

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
public void mapAllElements(String selector, String fieldName) {
    Elements elements = jsoupDocument.select(selector);
    for (int i = 0; i < elements.size(); i++) {
        Element element = elements.get(i);


        StringBuilder value = new StringBuilder();
        for(Element subElements : element.getAllElements()) {
            for (TextNode textNode : subElements.textNodes()) {
                final String text = textNode.text();
                value.append(text);
                value.append(" ");
            }
        }
        document.addField(fieldName, value.toString().trim());
    }
}
 
开发者ID:tblsoft,项目名称:solr-cmd-utils,代码行数:18,代码来源:HtmlJsoupFilter.java

示例8: getFirstNonEmptyNodeChild

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
public Node getFirstNonEmptyNodeChild(Element parent) {
    if (parent == null) return null;

    if (parent.childNodeSize() == 0) return null;

    if (parent.childNode(0) instanceof Element) {
        return parent.childNode(0);
    }

    if (parent.childNode(0) instanceof TextNode && ((TextNode) parent.childNode(0)).text().replaceAll("\u00A0", " ").trim().length() > 0) {
        return parent.childNode(0);
    }
    else {
        return getNextNonEmptyNode(parent.childNode(0));
    }

}
 
开发者ID:andyphillips404,项目名称:awplab-core,代码行数:18,代码来源:JsoupSession.java

示例9: getHtmlNode

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
public HtmlNode getHtmlNode(org.jsoup.nodes.Node node) {
	if(elementCache.containsKey(node)) {
		return elementCache.get(node);
	}
	else {
		HtmlNode htmlNode = null;
		if(node instanceof Element)
			htmlNode = new HtmlElement(page, (Element)node);
		else if(node instanceof TextNode)
			htmlNode = new HtmlTextNode(page, (TextNode)node);
		else
			htmlNode = new HtmlNode(page, node);
		elementCache.put(node, htmlNode);
		return htmlNode;
	}
}
 
开发者ID:Coffeeboys,项目名称:RenewPass,代码行数:17,代码来源:HtmlElements.java

示例10: initRawInfo

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
public void initRawInfo()
{
    StringBuilder sb = new StringBuilder();
    for (Node n : this) {
        //            NodeHelper.cleanEmptyElements(n);
        if (n instanceof TextNode) {
            this.setTagName(getPath(n));
            String nodeRawText = ((TextNode) n).text();
            sb.append(Utils.normalizeWhitespace(nodeRawText).trim());

            if (NodeHelper.isLink(n)) {
                charsCountInLinks += nodeRawText.length();
            }
        }
    }

    rawText = sb.toString();
}
 
开发者ID:UKPLab,项目名称:sigir2016-collection-for-focused-retrieval,代码行数:19,代码来源:Paragraph.java

示例11: getPath

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
public String getPath(Node n)
{
    String nodePath = "";
    while (n != null) {
        if (n instanceof TextNode) {
            n = n.parent();
        }
        if (NodeHelper.isInnerText(n)) {
            n = n.parent();
        }
        String parentNodeName = n.nodeName();
        nodePath = parentNodeName + "." + nodePath;

        if (!parentNodeName.equalsIgnoreCase("html")) {
            n = n.parent();
        }
        else {
            break;
        }
    }

    return nodePath;
}
 
开发者ID:UKPLab,项目名称:sigir2016-collection-for-focused-retrieval,代码行数:24,代码来源:Paragraph.java

示例12: initRawInfo

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
public void initRawInfo()
{
    StringBuilder sb = new StringBuilder();
    for (Node n : this) {
        //            NodeHelper.cleanEmptyElements(n);
        if (n instanceof TextNode) {
            this.setTagName(getPath(n));
            String nodeRawText = ((TextNode) n).text();
            sb.append(Utils.normalizeBreaks(nodeRawText).trim());

            if (NodeHelper.isLink(n)) {
                charsCountInLinks += nodeRawText.length();
            }
        }
    }

    rawText = sb.toString();
}
 
开发者ID:dkpro,项目名称:dkpro-c4corpus,代码行数:19,代码来源:Paragraph.java

示例13: head

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
public void head(Node node, int depth) {
    String name = node.nodeName();
    if (node instanceof TextNode)
        append(((TextNode) node).text()); // TextNodes carry all user-readable text in the DOM.
    else if (name.equals("li"))
        append("\n * ");
    else if (name.equals("dt"))
        append("  ");
    else if (StringUtil.in(name, "p", "h1", "h2", "h3", "h4", "h5", "tr"))
        append("\n");
}
 
开发者ID:cpusoft,项目名称:common,代码行数:12,代码来源:HtmlToPlainText.java

示例14: operate

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
@Override
public String operate(Element element) {
    int index = 0;
    StringBuilder accum = new StringBuilder();
    for (Node node : element.childNodes()) {
        if (node instanceof TextNode) {
            TextNode textNode = (TextNode) node;
            if (group == 0) {
                accum.append(textNode.text());
            } else if (++index == group) {
                return textNode.text();
            }
        }
    }
    return accum.toString();
}
 
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:17,代码来源:ElementOperator.java

示例15: extractIDString

import org.jsoup.nodes.TextNode; //导入依赖的package包/类
/**
 * Extract Date + ID + No
 * Ex: " 15/02/14(六)07:14:32 ID:F.OqpZFA No.6135732"
 * @return Post
 */
private Post extractIDString(Post post, TextNode node) {
    Pattern r = Pattern.compile("(\\d{2})/(\\d{2})/(\\d{2}).+?(\\d{2}):(\\d{2}):(\\d{2}) ID:([\\./0-9A-Za-z]+?) No\\.(\\d+)");
    Matcher m = r.matcher(node.text());
    if (m.find()) {
        Integer Y = Integer.parseInt(m.group(1)) + 2000, //year
                M = Integer.parseInt(m.group(2)) - 1, //month
                D = Integer.parseInt(m.group(3)), //day
                H = Integer.parseInt(m.group(4)), //hours
                I = Integer.parseInt(m.group(5)), //minutes
                S = Integer.parseInt(m.group(6)); //seconds
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Taipei"));
        cal.set(Y, M, D, H, I, S);
        post.date = cal;

        post.tripId = m.group(7);
        post.no = m.group(8);
    }

    return post;
}
 
开发者ID:touhonoob,项目名称:KomiReader,代码行数:26,代码来源:KomicaScraper.java


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