本文整理了Java中org.jsoup.nodes.Element.textNodes()
方法的一些代码示例,展示了Element.textNodes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.textNodes()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:textNodes
[英]Get this element's child text nodes. The list is unmodifiable but the text nodes may be manipulated.
This is effectively a filter on #childNodes() to get Text nodes.
[中]获取此元素的子文本节点。列表不可修改,但文本节点可能会被操纵。
这实际上是对#childNodes()的一个过滤器,用于获取文本节点。
代码示例来源:origin: org.jsoup/jsoup
@Override
public boolean matches(Element root, Element element) {
if (element instanceof PseudoTextElement)
return true;
List<TextNode> textNodes = element.textNodes();
for (TextNode textNode : textNodes) {
PseudoTextElement pel = new PseudoTextElement(
org.jsoup.parser.Tag.valueOf(element.tagName()), element.baseUri(), element.attributes());
textNode.replaceWith(pel);
pel.appendChild(textNode);
}
return false;
}
代码示例来源:origin: astamuse/asta4d
public List<TextNode> textNodes() {
return originElement.textNodes();
}
代码示例来源:origin: stackoverflow.com
//Select the <span> element the text "Logname"
Elements select = mHtml.select(".account-detail span.label:contains(Logname)");
//Get the element itself, since the select returns a list
Element lognameSpan = select.get(0);
//Get the <li> parent of the <span>
Element parent = lognameSpan.parent();
//Access the text node of the <li> directly since there is only one
String logname = parent.textNodes().get(0).text();
代码示例来源:origin: stackoverflow.com
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
public class HelloWorldWithJsoup {
public static void main(String[] args) {
String sentence = "Most implementations<img title=\"hello:\" alt=\"hello:{}\" src=\"http://images.doctissimo.fr/hello.gif\" class=\"wysiwyg_smiley\" /> provide ASDF as a module, and you can simply (require \"asdf\").";
Element body = Jsoup.parse(sentence).body();
for (TextNode textNode : body.textNodes()) {
textNode.wrap("<font color=\"white\"></font>");
}
System.out.println(body.html());
}
}
代码示例来源:origin: stackoverflow.com
removeText(Element node){
List<TextNode> textNodes = node.textNodes();
for(TextNode tn : textNode){
tn.remove();
}
Elements children = node.children();
for(Element e : Elements)
removeText(e);
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception{
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementsByClass("show").get(0).textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("booktext").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("contents").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("content").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + temp);
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: stackoverflow.com
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
for (Element el : doc.select("*")){
if (!el.ownText().isEmpty()){
for (TextNode node : el.textNodes())
node.remove();
}
}
System.out.println(doc);
代码示例来源:origin: ZhangQinhao/MONKOVEL
@Override
public String analyBookcontent(String s, String realUrl) throws Exception {
Document doc = Jsoup.parse(s);
List<TextNode> contentEs = doc.getElementById("BookText").textNodes();
StringBuilder content = new StringBuilder();
for (int i = 0; i < contentEs.size(); i++) {
String temp = contentEs.get(i).text().trim();
temp = temp.replaceAll(" ","").replaceAll(" ","");
if (temp.length() > 0) {
content.append("\u3000\u3000" + contentEs.get(i).text().trim().replaceAll(" ",""));
if (i < contentEs.size() - 1) {
content.append("\r\n");
}
}
}
return content.toString();
}
}
代码示例来源:origin: io.committed.krill/krill
@Override
public Document process(final Metadata metadata, final Document document) {
// If we have 1 node, it a p, it contains only text nodes, then treat it as pre
if (document.body().children().size() == 1) {
final Elements paragraphs = document.select("body > p");
if (paragraphs.size() == 1 && isAllTextNodes(paragraphs.first())) {
paragraphs.first().tagName("pre");
document.body().textNodes().forEach(TextNode::remove);
document.outputSettings().prettyPrint(false);
}
}
return document;
}
代码示例来源:origin: asciidoctor/asciidoctorj
@Test
public void ruby_treeprocessor_should_be_registered() {
this.asciidoctor.createGroup()
.loadRubyClass(getClass().getResourceAsStream("/ruby-extensions/shell-session-tree-processor.rb"))
.rubyTreeprocessor("ShellSessionTreeProcessor")
.register();
String content = this.asciidoctor.convert(
" $ echo \"Hello, World!\"\n" +
" > Hello, World!\n" +
"\n" +
" $ gem install asciidoctor",
options().toFile(false).get());
final Document document = Jsoup.parse(content);
final TextNode commandElement = document.getElementsByClass("command").get(0).textNodes().get(0);
assertThat(commandElement.getWholeText(), is("echo \"Hello, World!\""));
final TextNode commandElement2 = document.getElementsByClass("command").get(1).textNodes().get(0);
assertThat(commandElement2.getWholeText(), is("gem install asciidoctor"));
}
内容来源于网络,如有侵权,请联系作者删除!