本文整理了Java中org.jsoup.nodes.Element.childNode()
方法的一些代码示例,展示了Element.childNode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.childNode()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:childNode
暂无
代码示例来源:origin: iMeiji/Toutiao
if (script.contains("BASE_DATA.galleryInfo")) {
script = e.childNode(0).toString();
代码示例来源:origin: stackoverflow.com
String html = "<span style=\"font-weight:bold;\">bold.</span><span></span><span><a>text</a></span>";
Document parsedDoc = Jsoup.parse(html);
Elements selects = parsedDoc.select("span");
for (Element span : selects) {
List<Node> childNodes = span.childNodes();
if (childNodes.size() > 0 && span.childNode(0).childNodes().size() == 0) {
span.childNode(0).wrap("<p>");
}
}
代码示例来源:origin: stackoverflow.com
// can only grab first 100 results
String userAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36";
String url = "https://www.google.com/search?site=imghp&tbm=isch&source=hp&q=kittens&gws_rd=cr";
List<String> resultUrls = new ArrayList<String>();
try {
Document doc = Jsoup.connect(url).userAgent(userAgent).referrer("https://www.google.com/").get();
Elements elements = doc.select("div.rg_meta");
JSONObject jsonObject;
for (Element element : elements) {
if (element.childNodeSize() > 0) {
jsonObject = (JSONObject) new JSONParser().parse(element.childNode(0).toString());
resultUrls.add((String) jsonObject.get("ou"));
}
}
System.out.println("number of results: " + resultUrls.size());
for (String imageUrl : resultUrls) {
System.out.println(imageUrl);
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
代码示例来源:origin: perfectsense/dari
Node next = body.childNode(0);
代码示例来源:origin: perfectsense/brightspot-cms
Node next = body.childNode(0);
代码示例来源:origin: crazyacking/zeekEye
/**
* 从子div中获取转发原因
*
* @param processEl
* @return
*/
private static String getRepostReason(Element processEl) {
StringBuilder repostReason = new StringBuilder();
int endIndex = processEl.childNodes().size() - BACK_NODES_NUM_IN_REPOST_DIV;
for (int i = 1; i < endIndex; i++) {
repostReason.append(processEl.childNode(i).toString());
}
return repostReason.toString();
}
代码示例来源:origin: ch.digitalfondue.stampo/stampo
String contentWithTransformedHeading(List<HeaderWithPosition> globalToc, boolean addNumberingToTitles) {
if (addNumberingToTitles && PathUtils.isHtml(page.outputPath)) {
List<HeaderWithPosition> summary = globalToc.subList(summaryPositionStart, summaryPositionEnd);
Document doc = Jsoup.parse(page.content());
Elements titles = doc.select("h1,h2,h3,h4,h5,h6");
for (int i = 0; i < summary.size() && i < titles.size(); i++) {
Element h = titles.get(i);
String tocNumber = "<span class=\"stampo-heading-toc-number\">"+ summary.get(i).positions.stream().map(Object::toString).collect(Collectors.joining(".")) + "</span>";
if(h.childNodeSize() > 0) {
h.childNode(0).before(tocNumber);
} else {
h.append(tocNumber);
}
}
return doc.html();
} else {
return page.content();
}
}
代码示例来源:origin: astamuse/asta4d
public Node childNode(int index) {
return originElement.childNode(index);
}
代码示例来源:origin: com.sdl.dxa/dxa-tridion-provider
/**
* <p>propertyXpmMarkupAlreadyGenerated.</p>
*
* @param propertyElement a {@link org.jsoup.nodes.Element} object.
* @return a boolean.
*/
protected static boolean propertyXpmMarkupAlreadyGenerated(Element propertyElement) {
int index = 0;
Node node = null;
while (index < propertyElement.childNodes().size()) {
node = propertyElement.childNode(index);
if (!(node instanceof TextNode)) {
break;
}
index++;
}
if (node != null && node instanceof Comment) {
Comment comment = (Comment) node;
if (comment.getData().contains("Start Component Field:")) {
return true;
}
}
return false;
}
代码示例来源:origin: chimbori/crux
private static void removeShortParagraphs(Element topNode) {
for (int i = topNode.childNodeSize() - 1; i >= 0; i--) {
Node childNode = topNode.childNode(i);
String text = null;
boolean isExemptFromMinTextLengthCheck = false;
if (childNode instanceof TextNode) {
text = ((TextNode) childNode).text().trim();
} else if (childNode instanceof Element) {
Element childElement = (Element) childNode;
text = childElement.text().trim();
isExemptFromMinTextLengthCheck = TAGS_EXEMPT_FROM_MIN_LENGTH_CHECK.contains(childElement.tagName());
}
Log.i("removeShortParagraphs: [%s] isExemptFromMinTextLengthCheck : %b", childNode, isExemptFromMinTextLengthCheck);
if (text == null ||
text.isEmpty() ||
(!isExemptFromMinTextLengthCheck && text.length() < MIN_LENGTH_FOR_PARAGRAPHS) ||
text.length() > StringUtils.countLetters(text) * 2) {
Log.printAndRemove(childNode, "removeShortParagraphs:");
}
}
}
代码示例来源:origin: stackoverflow.com
final Document doc = Jsoup.parse(new File(".\\source.xhtml"), "UTF-8");
for (Element result : doc.select("div")) {
final String text = ((TextNode) result.childNode(0)).getWholeText();
System.out.println(text);
}
代码示例来源:origin: theonedev/onedev
public static Collection<Long> parseFixedIssues(Project project, String commitMessage) {
Collection<Long> issueNumbers = new HashSet<>();
/*
* Transform commit message with defined transformers first in order not to process issue keys pointing
* to external issue trackers
*/
commitMessage = CommitMessageTransformer.transform(commitMessage, project.getCommitMessageTransforms());
// Only process top level text node to skip transformed links above
Element body = Jsoup.parseBodyFragment(commitMessage).body();
for (int i=0; i<body.childNodeSize(); i++) {
Node node = body.childNode(i);
if (node instanceof TextNode) {
TextNode textNode = (TextNode) body.childNode(i);
StringTokenizer tokenizer = new StringTokenizer(textNode.getWholeText());
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
if (FIX_ISSUE_WORDS.contains(token.toLowerCase())) {
while (FIX_ISSUE_WORDS.contains(parseIssueNumbers(tokenizer, issueNumbers)))
parseIssueNumbers(tokenizer, issueNumbers);
}
}
}
}
return issueNumbers;
}
代码示例来源:origin: stackoverflow.com
String htmlString = "<html><body><table><td> SCH4UE-01 : Chemistry <br> Block: 1 - rm. 315 <br></td></table></body></html>";
Document doc = Jsoup.parse(htmlString);
Elements tdElements = doc.select("td");
for (Element tdElement : tdElements){
System.out.println(tdElement.childNode(0));
}
代码示例来源:origin: theonedev/onedev
StringBuffer html = new StringBuffer();
for (int i=0; i<body.childNodeSize(); i++) {
Node node = body.childNode(i);
if (node instanceof TextNode) {
TextNode textNode = (TextNode) body.childNode(i);
Matcher matcher = entityInfoProvider.getPattern().matcher(textNode.getWholeText());
StringBuffer buffer = new StringBuffer();
代码示例来源:origin: stackoverflow.com
String html = "<div>hfhfk<bloquotes><bloquotes>ppppp</bloquotes>fin texte </bloquotes></div>";
Document doc = Jsoup.parse(html);
Elements source = doc.select("div");
Element element = (Element) source.get(0);
Node result = element.childNode(0);
String nodeResult = result.toString().trim();
System.out.println(nodeResult + "");
System.out.println(nodeResult.length() + "");
代码示例来源:origin: theonedev/onedev
Element body = Jsoup.parseBodyFragment(commitMessage).body();
for (int i=0; i<body.childNodeSize(); i++) {
if (body.childNode(i) instanceof TextNode) {
TextNode textNode = (TextNode) body.childNode(i);
Element element = new Element(Tag.valueOf("a"), "");
element.addClass("commit");
代码示例来源:origin: stackoverflow.com
String name = divTag.childNode(0).toString();
name = name.split("Flamingnet Student Book Reviewer")[1].trim(); // Cut off, the things not needed
StringBuilder text = new StringBuilder(divTag.childNode(2).toString().trim()); // Text is constructed from two tags
text.append(divTag.select("p").first().text().trim()); // 2nd Part (thats the one in p-tag)
代码示例来源:origin: com.atlassian.mail/atlassian-mail
String removedWhitespace = EMPTY;
final Node firstChildNode = element.childNodeSize() > 0 ? element.childNode(0) : null;
代码示例来源: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: opacapp/opacclient
if (tr.child(1).childNode(0) instanceof Comment) {
Comment c = (Comment) tr.child(1).childNode(0);
String comment = c.getData().trim();
String id = comment.split(": ")[1];
内容来源于网络,如有侵权,请联系作者删除!