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

x33g5p2x  于2022-01-18 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(202)

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

Element.previousSibling介绍

暂无

代码示例

代码示例来源:origin: astamuse/asta4d

public Node previousSibling() {
  return originElement.previousSibling();
}

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

String html = "<!-- some comment --><div class=\"someDiv\">... other html</div><!-- some comment 2 --><div class=\"someDiv\">... other html</div>";
Document doc = Jsoup.parseBodyFragment(html);
Elements elements = doc.select(".someDiv");
for (Element element : elements) {
  System.out.println(((Comment) element.previousSibling()).getData());
}

代码示例来源:origin: java-webbee/web-bee

@Override
public String prevNodeText(){
  if(element==null){
    return null;
  }
  return element.previousSibling().toString();
}

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

String html = // your html here

Document doc = Jsoup.parse(html);
Elements elements = doc.select("b + img");

for( Element e : elements )
{
  Node value = e.previousSibling();

  // eg. print the node, here the output is 104 and 8
  System.out.println(value.toString());
}

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

@Override
public Node getPreviousSibling() {
  return NodeAdaptors.getNode(element.previousSibling());
}

代码示例来源:origin: us.codecraft/xsoup

@Override
public Node getPreviousSibling() {
  return NodeAdaptors.getNode(element.previousSibling());
}

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

String source = "<u>Download Instructions:</u><br/><a class=\"postlink\" href=\"https://1test.com/info\">https://test.com/info</a><br/><a class=\"postlink\" href=\"https://2test.com/info\">https://test.com/info</a><br/><a class=\"postlink\" href=\"https://3test.com/info\">https://test.com/info</a><br/>Mirror:<br/><a class=\"postlink\" href=\"http://global.eu/navi1.html\">http://global.eu/navi.html</a><br/><a class=\"postlink\" href=\"http://global.eu/navi2.html\">http://global.eu/navi.html</a><br/>Additional:<br/><a class=\"postlink\" href=\"http://main.org/navi.html\">http://main.org/navi.html</a>";

Document doc = Jsoup.parse(source, "UTF-8");

List<String> downloadInstructionsUrls = new ArrayList<>();
List<String> mirrorUrls = new ArrayList<>();

for (Element el : doc.select("a.postlink")) {
  Node previousSibling = el.previousSibling();

  while( !(previousSibling.nodeName().equals("u") || previousSibling.nodeName().equals("#text")) ){
    previousSibling = previousSibling.previousSibling();
  }

  String identifier = previousSibling.toString();

  if(identifier.contains("Download Instructions")){
    downloadInstructionsUrls.add(el.attr("abs:href"));
  }else if(identifier.toString().contains("Mirror")){
    mirrorUrls.add(el.attr("abs:href"));
  }
}

System.out.println("Url for download instructions:");
downloadInstructionsUrls.forEach(url -> {System.out.println("\t"+url);});
System.out.println("Url for mirror:");
mirrorUrls.forEach(url -> {System.out.println("\t"+url);});

代码示例来源:origin: chimbori/crux

private static void replaceLineBreaksWithSpaces(Element topNode) {
 for (Element brNextToBrElement : topNode.select("br + br")) {
  brNextToBrElement.remove();
 }
 for (Element brElement : topNode.select("br")) {
  if (brElement.previousSibling() != null) {
   brElement.previousSibling().after(" • ");
  } else {
   brElement.parent().append(" • ");
  }
  brElement.unwrap();
 }
}

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

private void removeWhitespaceBefore(Element element) {
  Node previousSibling = element.previousSibling();
  if (previousSibling instanceof TextNode) {
    TextNode textNode = (TextNode) previousSibling;
    String text = textNode.getWholeText();
    int startOfTrailingWhitespace = lastIndexOfNonWhitespace(text) + 1;
    if (startOfTrailingWhitespace <= 0) {
      textNode.remove();
    } else if (startOfTrailingWhitespace < text.length()) {
      textNode.splitText(startOfTrailingWhitespace);
      textNode.nextSibling().remove();
    }
  }
}

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

if(!iwe.isEmphasisPreserved() || iwe.isAdditionalSpacingNeeded()) {
  Node n = node.previousSibling();
  if(n != null && n instanceof TextNode) {
    TextNode tn = (TextNode)n;

代码示例来源:origin: com.vaadin.addon/vaadin-touchkit-agpl

Element head = document.getElementsByTag("head").get(0);
DocumentType doctype = (DocumentType) html.previousSibling();
DocumentType html5doc = new DocumentType("html", "", "", "");
doctype.replaceWith(html5doc);

代码示例来源:origin: perfectsense/brightspot-cms

List<Node> beforeChildren = new ArrayList<>();
for (Node previous = enhancement.previousSibling();
     previous != null;
     previous = previous.previousSibling()) {

代码示例来源:origin: perfectsense/dari

List<Node> beforeChildren = new ArrayList<Node>();
for (Node previous = enhancement.previousSibling();
    previous != null;
    previous = previous.previousSibling()) {

相关文章

Element类方法