org.jsoup.nodes.TextNode.text()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中org.jsoup.nodes.TextNode.text()方法的一些代码示例,展示了TextNode.text()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextNode.text()方法的具体详情如下:
包路径:org.jsoup.nodes.TextNode
类名称:TextNode
方法名:text

TextNode.text介绍

[英]Get the text content of this text node.
[中]获取此文本节点的文本内容。

代码示例

代码示例来源:origin: code4craft/webmagic

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();
}

代码示例来源:origin: org.jsoup/jsoup

/**
 * Split this text node into two nodes at the specified string offset. After splitting, this node will contain the
 * original text up to the offset, and will have a new text node sibling containing the text after the offset.
 * @param offset string offset point to split node at.
 * @return the newly created text node containing the text after the offset.
 */
public TextNode splitText(int offset) {
  final String text = coreValue();
  Validate.isTrue(offset >= 0, "Split offset must be not be negative");
  Validate.isTrue(offset < text.length(), "Split offset must not be greater than current text length");
  String head = text.substring(0, offset);
  String tail = text.substring(offset);
  text(head);
  TextNode tailNode = new TextNode(tail);
  if (parent() != null)
    parent().addChildren(siblingIndex()+1, tailNode);
  return tailNode;
}

代码示例来源:origin: vsch/flexmark-java

private boolean processText(FormattingAppendable out, TextNode node) {
  skip();
  if (out.isPreFormatted()) {
    out.append(prepareText(node.getWholeText(), true));
  } else {
    out.append(prepareText(node.text()));
  }
  return true;
}

代码示例来源:origin: stackoverflow.com

public static String getTextAfterTag(Element ele) {
 String text = "";
 for(TextNode node: ele.textNodes()) {
  text += node.text();
 }
 return text;
}

代码示例来源:origin: stackoverflow.com

for (Element el : doc.select("body").select("*")) {
   for (TextNode node : el.textNodes()) {
         node.text() ));
   }
 }

代码示例来源:origin: stackoverflow.com

List<TextNode> bodyTextNode = doc.getElementById("content").textNodes();
 String html = "";
 for(TextNode txNode:bodyTextNode){
   html+=txNode.text();
 }

代码示例来源:origin: GistLabs/mechanize

public static String getAttributeValueOfJSoupTextNode(TextNode textNode,
    String attribute) {
  if(attribute.equals(HtmlSpecialAttributes.SPECIAL_ATTRIBUTE_TEXT))
    return textNode.text();
  else
    return null;
}

代码示例来源:origin: stackoverflow.com

Elements textElements = document.select("h1, p");

for (Element e : textElements.select("*")) {
  for (TextNode tn : e.textNodes()) {
    tn.text(tn.text().toUpperCase());
  }
}

代码示例来源:origin: com.cognifide.aet/jobs

@Override
 public void visit(Node node) {
  if (node instanceof TextNode) {
   String text = ((TextNode) node).text();
   if (StringUtils.isNotBlank(text)) {
    formattedTextBuilder.append(text).append("\n");
   }
  }
 }
}

代码示例来源:origin: Cognifide/aet

@Override
 public void visit(Node node) {
  if (node instanceof TextNode) {
   String text = ((TextNode) node).text();
   if (StringUtils.isNotBlank(text)) {
    formattedTextBuilder.append(text).append("\n");
   }
  }
 }
}

代码示例来源:origin: com.cv4j.netdiscovery/netdiscovery-core

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();
}

代码示例来源:origin: us.codecraft/webmagic-core

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();
}

代码示例来源:origin: stackoverflow.com

final String html = "<p> Hi everyone. This is a <em>dead end.</em> Do not go!</p>";

Document doc = Jsoup.parseBodyFragment(html); // Parse html into a document
Element pTag = doc.select("p").first(); // Select the p-element (there's just one)

// Text before 'em'-tag
TextNode preEM = (TextNode) pTag.childNode(0);
preEM.text(preEM.text().replace("This is a", "This is not a"));

// Text after 'em'-tag
TextNode postEM = (TextNode) pTag.childNode(2);
postEM.text("You may go!");

System.out.println(pTag); // Print result

代码示例来源:origin: org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext

@Override
public void process(java.util.Stack<NodeHandler> stack, ContentHandler contentHandler) throws SAXException {
  String text = isPreserveWhitespace() ? node.getWholeText() : node.text();
  contentHandler.characters(text.toCharArray(), 0, text.length());
}

代码示例来源:origin: stackoverflow.com

final String html = "<div class=example>Text #1</div> \"Another Text 1\"\n"
         + "<div class=example>Text #2</div> \"Another Text 2\" ";

Document doc = Jsoup.parse(html);

for( Element element : doc.select("div.example") ) // Select all the div tags
{
  TextNode next = (TextNode) element.nextSibling(); // Get the next node of each div as a TextNode

  System.out.println(next.text()); // Print the text of the TextNode
}

代码示例来源:origin: jungilhan/awesome-blogs-android

private static int calculateLength(Element el, int depth) {
  int result = 0;
  for(final Node n : el.childNodes()) {
    if(n instanceof Element) {
      result += (4 * depth) + calculateLength((Element)n, depth+1);
    } else if(n instanceof TextNode) {
      result += ((TextNode)n).text().length();
    }
  }
  return result;
}

代码示例来源:origin: GistLabs/mechanize

@Override
public String getAttribute(String attributeKey) {
  if(attributeKey.equals(HtmlSpecialAttributes.SPECIAL_ATTRIBUTE_TEXT))
    return getJsoupTextNode().text();
  else
    return super.getAttribute(attributeKey);
}

代码示例来源:origin: jungilhan/awesome-blogs-android

@Override
public void handleTextNode(TextNode node, DocumentConverter converter) {
  // Override to provide special handling for ignoring
  // leading or trailing all-space nodes.
  if((node.previousSibling() != null && node.nextSibling() != null) ||
        node.text().trim().length() != 0) {
    super.handleTextNode(node, converter);
  }
}

代码示例来源:origin: de.unistuttgart.ims/uimautil

public void head(Node node, int depth) {
  if (node.getClass().equals(TextNode.class)) {
    if (this.preserveWhitespace)
      builder.add(((TextNode) node).getWholeText());
    else
      builder.add(((TextNode) node).text());
  } else {
    beginMap.put(node, builder.getPosition());
  }
}

代码示例来源:origin: de.unistuttgart.ims.uima.io/generic-xml-reader

@Override
public void head(Node node, int depth) {
  if (node instanceof TextNode) {
    if (this.preserveWhitespace)
      builder.add(((TextNode) node).getWholeText());
    else
      builder.add(((TextNode) node).text());
  } else {
    beginMap.put(node, builder.getPosition());
  }
}

相关文章