本文整理匯總了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;
}
示例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");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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());
}
}
示例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));
}
}
示例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;
}
}
示例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();
}
示例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;
}
示例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();
}
示例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");
}
示例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();
}
示例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;
}