List of usage examples for org.jsoup.nodes Element children
public Elements children()
From source file:Main.java
public static Element findFirstChildElement(Element element, String name) { List<Element> children = element.children(); for (Element child : children) { if (child.nodeName().equalsIgnoreCase(name)) { return child; }/* www. ja va2 s .c o m*/ } return null; }
From source file:Main.java
public static String getText(final Element element) { Element textTag = element; while (!textTag.hasText() && textTag.children().size() > 0) { textTag = textTag.children().get(0); }/*from w ww.j a v a2 s . c o m*/ return textTag.text(); }
From source file:Main.java
public static String textFromChildAt(final Element element, final int index) { return textFromChildAt(element.children(), index); }
From source file:edu.ucla.cs.scai.swim.qa.ontology.dbpedia.tipicality.DbpediaCsvDownload.java
private static void download(Element e) throws MalformedURLException, IOException { for (Element c : e.children()) { String tagName = c.tag().getName(); if (tagName.equals("small")) { for (Element c1 : c.children()) { if (c1.tag().getName().equals("a") && c1.text().equalsIgnoreCase("csv")) { String href = c1.attr("href"); System.out.println("Downloading " + href); try { URL remoteFile = new URL(href); ReadableByteChannel rbc = Channels.newChannel(remoteFile.openStream()); String[] s = href.split("\\/"); FileOutputStream fos = new FileOutputStream( DBpediaOntology.DBPEDIA_CSV_FOLDER + s[s.length - 1]); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } catch (Exception ex) { ex.printStackTrace(); }//w w w.ja va 2 s . c o m } } } else if (tagName.equals("ul")) { for (Element c1 : c.children()) { if (c1.tagName().equals("li")) { download(c1); } } } } }
From source file:io.github.carlomicieli.footballdb.starter.parsers.Parser.java
protected static Optional<String> valueFromChild(Element e, int index) { Elements children = e.children(); if (index > children.size()) return Optional.empty(); return Optional.ofNullable(children.get(index).text()); }
From source file:com.gistlabs.mechanize.document.html.JsoupDataUtil.java
private static void filterElementsByTag(List<Element> results, Element element, Set<String> tagSet) { if (tagSet.contains(element.tag().getName().toLowerCase())) results.add(element);/* w w w. ja va 2 s . c om*/ for (Element child : element.children()) filterElementsByTag(results, child, tagSet); }
From source file:io.github.carlomicieli.footballdb.starter.parsers.TeamRosterParser.java
private static Map<String, String> rosterEntryValues(Element e) { Map<String, String> values = new HashMap<>(); values.put("number", childValueAsString(e, 0).orElse(null)); values.put("profile", e.children().get(1).getElementsByTag("a").attr("href")); values.put("name", e.children().get(1).getElementsByTag("a").text()); values.put("position", childValueAsString(e, 2).orElse(null)); values.put("status", childValueAsString(e, 3).orElse(null)); values.put("height", childValueAsString(e, 4).orElse(null)); values.put("weight", childValueAsString(e, 5).orElse(null)); values.put("birth_date", childValueAsString(e, 6).orElse(null)); values.put("exp", childValueAsString(e, 7).orElse(null)); values.put("college", childValueAsString(e, 8).orElse(null)); return Collections.unmodifiableMap(values); }
From source file:io.sightly.tck.html.HTMLExtractor.java
/** * Checks if the element matched by the {@code selector} has children and if their number is equal to {@code howMany}. * * @param url the url that identifies the markup * @param markup the markup/*w w w . j av a 2 s.c o m*/ * @param selector the selector used for retrieval * @param howMany the number of expected children * @return {@code true} if the number of children is equal to {@code howMany}, {@code false} otherwise */ public static boolean hasChildren(String url, String markup, String selector, int howMany) { ensureMarkup(url, markup); Document document = documents.get(url); Element element = document.select(selector).first(); if (element == null) { return false; } return element.children().size() == howMany; }
From source file:Main.java
public static String printNode(Element root, int indentation) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < indentation; i++) { sb.append(' '); }/* ww w . j a v a 2 s .c o m*/ sb.append(root.tagName()); sb.append(":"); sb.append(root.ownText()); sb.append("\n"); for (Element el : root.children()) { sb.append(printNode(el, indentation + 1)); sb.append("\n"); } return sb.toString(); }
From source file:Main.java
private static String printNode(Element root, int indentation) { StringBuilder sb = new StringBuilder(indentation); for (int i = 0; i < indentation; i++) { sb.append(' '); }// w ww . j a v a 2 s. co m sb.append(root.tagName()); sb.append(':'); sb.append(root.ownText()); sb.append('\n'); for (Element el : root.children()) { sb.append(printNode(el, indentation + 1)); sb.append('\n'); } return sb.toString(); }