Document document = Jsoup.connect(url).get(); Elements eles = doc.select("pre"); for (Element ele : eles) { System.out.println(ele.toString()); }
public static Element writeElementList(final String tag, final Collection<?> c) { final Element el = new Element(tag); try { el.addContent(c); } catch (final IllegalAddException e) { LOGGER.warn(e + ": " + el.toString(), e); } return el; }
for (int i = 0; i < elements.size(); i++) { Element sibling = siblings.get(i); if ("table".equals(sibling.tagName())) { siblings.remove(i); Element button = Jsoup.parse("<button type='button'>Click Me!</button>"); sibling = button; sb.append(sibling.toString()); } else { sb.append(sibling.toString()); } }
public static List<String> parseForMeta(String htmlText) { Document jsDocument = Jsoup.parse(htmlText); Elements metaElements = jsDocument.select("meta[name]"); List<String> metaList = new ArrayList<String>(); for (Element element : metaElements) { metaList.add(element.toString()); } return metaList; }
Document doc = Jsoup.connect(...).get(); for( Element e : doc.select("a[href]") ) // Select all 'a'-Tags with 'href' attribute { String wholeTag = e.toString(); // Get a string as the element is /* No you you can use the html - in this example for a simple output */ System.out.println(wholeTag); }
for(SyndEntry entry : feed.getEntries()) { for (Element element : entry.getForeignMarkup()) { System.out.println("element: " + element.toString()); } }
Elements elements = doc.select("h1,h2,h3,h4,h5"); for (Element element : elements) { StringBuilder sb = new StringBuilder(element.toString()); Element next = element.nextElementSibling(); while (next != null && !next.tagName().startsWith("h")) { sb.append(next.toString()).append("\n"); next = next.nextElementSibling(); } System.out.println(sb); }
@Override public void ingest(Context context, DSpaceObject dso, Element root, boolean createMissingMetadataFields) throws CrosswalkException, IOException, SQLException, AuthorizeException { if (!(root.getName().equals("premis"))) { throw new MetadataValidationException("Wrong root element for PREMIS: " + root.toString()); } ingest(context, dso, root.getChildren(), createMissingMetadataFields); }
Elements divs = doc.select("div.sports_FfCell"); //gets the div part that has the information you want. for (Element div : divs) { if (div.toString().contains("market")) //there is a market tag for the table labels (sports_FfCell market). System.out.print(div.text() + " - "); //no new line after the winner text. else System.out.println(div.text().replace("MULTI", "- ")); //it gets the MULTI part too, so i replace it. }
String html="<html><body><div class=\"main\">" + "<div class=\"sub\"> sub </div>" + "main </div></body></html>"; Document doc=Jsoup.parse(html); Elements divs=doc.select("*"); for(Element div : divs){ System.out.println(div.tag() + ":\n" + div.toString()); System.out.println("---"); }
URL url = new URL("http://www.myurl.com"); Document doc = Jsoup.parse(url, 3000); // This should work now Element tables = doc.select("table tr .id"); // This propably should work too Element tables2 = doc.select("table tr[class*=id]"); for(Element table : tables) { System.out.println(table.toString()); }
private String getTextContent(Element elem) { String text = elem.getContent().toString(); final List<Element> children = elem.getChildElements(); for (Element child : children) { text = text.replace(child.toString(), ""); } return text; }
final String html = "<b><script>your script here</script></b>"; Document doc = Jsoup.parse(html); for( Element element : doc.select("script") ) { element.replaceWith(TextNode.createFromEncoded(element.toString(), null)); } System.out.println(doc);
protected void onPostExecute(Elements result) { print("\nLinks: (%d)", result.size()); for (Element link : result) { //view.setText((CharSequence) link); view.setText(link.toString()); print(" * a: <%s> (%s)", link.attr("abs:href"), trim(link.text(), 35)); } }
Elements e = doc.select("table#scheuletbl > tbody > tr > td"); for (Element el : e) { if (el.hasClass("separator2")) System.out.println(el.text()); // cinema name else if (el.toString().contains("colspan=\"2\"")) System.out.println(el.text()); // date else if (el.hasAttr("rel")) System.out.println(el.text()); // times }
public String escapeHtml(String source) { Document doc = Jsoup.parseBodyFragment(source); Elements elements = doc.select("b"); for (Element element : elements) { element.replaceWith(new TextNode(element.toString(),"")); } return Jsoup.clean(doc.body().toString(), new Whitelist().addTags("a").addAttributes("a", "href", "name", "rel", "target")); }
Document documentImage2 = Jsoup.connect(urls[0]).get(); // Using Elements to get the class data Element div = documentImage2.select("div[class=content]").get(1); Document doc_i = Jsoup.parse(div.toString()); Elements image = doc_i.select("img"); String imgSrcImage2 = image.html();