public static void main(String... args) throws IOException { Document document = Jsoup.parse("<div>" + "<a href=\"#\"> I don't want this text </a>" + "**I want to retrieve this text**" + "</div>"); Element a = document.select("a").first(); Node node = a.nextSibling(); System.out.println(node.toString()); }
public static void main(String[] args) throws IOException { String str = "<div>" + " Some text <b>with tags</b> might go here." + " <p>Also there are paragraphs</p>" + " More text can go without paragraphs<br/>" + "</div>"; Document doc = Jsoup.parse(str); Element div = doc.select("div").first(); int i = 0; for (Node node : div.childNodes()) { i++; System.out.println(String.format("%d %s %s", i, node.getClass().getSimpleName(), node.toString())); } }
@Override public String toString() { String res = "["; Node current = this.head; while(current != null) { res += current.toString() + "\t"; current = current.next; } res += "]"; return res; }
Node parent = doc.getElementsByTagName("your_tag").item(i).getParentNode(); if (parent.toString().equalsIgnoreCase("your_parent_node")) { parentCnt++; }
public String toString() { String output = ""; for(Node node: id) output+=node.toString(); return output; }
for( Node n : doc.body().childNodes() ) { if( n instanceof TextNode ) { str = n.toString().trim(); if( str.toLowerCase().startsWith("alex") ) // Node 'Alex' { String t[] = n.toString().split(","); // you have an array with each word as string now System.out.println(Arrays.toString(t)); // eg. output } } }
Node head = new Node(3, second); Node node = head; while (node.next != null) { System.out.println(node.toString()); node = node.next; }
ArrayList<Node> list = new ArrayList<>(); for(int i = 0; i < edit.linesInFile(); i++{ list.add(new Node(edit.getLine()); } for(Node n: list){ System.out.println(n.toString()) } return list;
final String html = "This is an <b>important</b> line and i <b>want</b> formatting in it"; Document doc = Jsoup.parse(html); for( Node node : doc.body().childNodes() ) { System.out.println(node.toString()); }
public void walk_list(LinkedList<Node> list){ //the poll method retrieves and removes the head of the list //if the list is empty, it returns null Node n = list.poll(); //Base case - list is empty if(n == null){ return; } System.out.println(n.toString()); walk_list(list); }
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()); }
public String toString() { if (head == null) { return ""; } String result = ""; Node temp = head; do { result += temp.toString(); temp = temp.getNextNode(); } while (head != tail && temp != head); return result; }
public String toString() { Node tmp = head; String result = ""; while (tmp != null) { result += tmp.toString() + " "; tmp = tmp.getNext(); } return result; }
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() + "");
Elements addresses = doc.select("address > :not(div[class=phone])"); for (Element address : addresses) { for (Node node : address.childNodes()) { if (node.nodeName().equals("br")) { continue; } String text = node.toString().trim(); System.out.println(text); } }
public void preorderTraverseTree(Node focusNode) { if (focusNode != null) { System.out.print(focusNode.toString()); preorderTraverseTree(focusNode.leftChild); preorderTraverseTree(focusNode.rightChild); } }
Document doc = Jsoup.parse(str); Element div = doc.select("div").first(); for (Node node : div.childNodes()) { if (node instanceof org.jsoup.nodes.TextNode) { System.out.println(node.toString(); } }
private void FourWaySearch(Node c) { if (c.row < 0 || c.row > ROWS - 1 || c.col < 0 || c.col > COLS - 1 || c.hasParent(c.row,c.col)) return; else { c.data = grid[c.row][c.col]; //get the string value from the word search grid if(dictionary.contains(c.toString())) foundWords.add(c.toString()); FourWaySearch(new Node(c,c.row-1,c.col)); FourWaySearch(new Node(c,c.row,c.col-1)); FourWaySearch(new Node(c,c.row+1,c.col)); FourWaySearch(new Node(c,c.row,c.col+1)); } }
// You need to get Nodes, not Elements Document doc = Jsoup.parse(str); Element div = doc.select("div").first(); for (Node node : div.childNodes()) { System.out.println( String.format( "%s %s", node.getClass().getSimpleName(), node.toString() ) ); }