document = Jsoup.connect("http://rads.stackoverflow.com/amzn/click/B0051HDDO2").timeout(20000).get(); Elements elements =document.select(".prod_image_selector"); for (Element element : elements){ Attributes imageAttributes=element.attributes(); for (Attribute attribute: imageAttributes){ if(attribute.getKey().equals("src")){ String imageURL=attribute.getValue(); } } }
String xml = "<output transactionId=\"53264089\"\r\n" + " paymentId=\"21575285\"\r\n" + " amount=\"52.78\"\r\n" + " dateTime=\"2013-12-13 15:04:42\"\r\n" + " mode=\"TEST\"\r\n" + " referenceNo=\"80001186\"\r\n" + " transactionType=\"Authorized\"\r\n" + " status=\"Processed\"\r\n" + " isFlagged=\"NO\" />"; Document doc = Jsoup.parse(xml, "", Parser.xmlParser()); Attributes attr = doc.select("output").first().attributes(); for (Attribute a : attr) System.out.printf("%-15s -> %s%n", a.getKey(), a.getValue());
String url = "http://stackoverflow.com/questions/7311269" + "/java-print-any-detail-of-html-element"; Document doc = Jsoup.connect(url).get(); Elements divs = doc.select("div"); int i = 0; for (Element div : divs) { System.out.format("Div #%d:\n", ++i); for(Attribute attr : div.attributes()) { System.out.format("%s = %s\n", attr.getKey(), attr.getValue()); } }
protected boolean isSafeAttribute(String tagName, Element el, Attribute attr) { return ("img".equals(tagName) && "src".equals(attr.getKey()) && attr.getValue().startsWith("data:;base64")) || super.isSafeAttribute(tagName, el, attr);
Document doc = Jsoup.parse(html_contents); for (Element element : doc.getAllElements()) { for (Attribute attribute : element.attributes()) { if(attribute.getKey().equalsIgnoreCase("alt")) { names.add(attribute.getValue()); } } }
Document doc = Jsoup.parseBodyFragment(htmlString); Elements inputs = doc.select("input"); for (Element el : inputs) { Attributes attrs = el.attributes(); System.out.print("ELEMENT: " + el.tagName()); for (Attribute attr : attrs) { System.out.print(" " + attr.getKey() + "=" + attr.getValue()); } System.out.println(); }
Document doc = Jsoup.parse("<incident last-updated-dt='1401950400000' longitude='146.56256387822685' latitude='-38.39289894161029' resource-count='0' incident-no='58'>"); Element element = doc.select("incident").first(); String tagName = element.tagName(); System.out.println("Tag name : " + tagName); for(Attribute attr : element.attributes()) { System.out.println(attr.getKey() + " : " + attr.getValue()); }
public static void main(String[] args) { for (Node node : Parser.parseFragment("<test><author name=\"Vlad\"><book name=\"SO\"/>" , new Element(Tag.valueOf("p"), ""), "")) { print(node, 0); } } public static void print(Node node, int offset) { for (int i = 0; i < offset; i++) { System.out.print(" "); } System.out.print(node.nodeName()); for (Attribute attribute: node.attributes()) { System.out.print(", "); System.out.print(attribute.getKey() + "=" + attribute.getValue()); } System.out.println(); for (Node child : node.childNodes()) { print(child, offset + 4); } }
Document doc = Jsoup.parse(html); Elements e = doc.getElementsByTag("body"); Log.i("Span element: "+e.get(0).nodeName(), ""+e.get(0).nodeName()); e = e.get(0).getElementsByTag("span"); Attributes styleAtt = e.get(0).attributes(); Attribute a = styleAtt.asList().get(0); if(a.getKey().equals("style")){ String[] items = a.getValue().trim().split(";"); String newValue = ""; for(String item: items){ if(item.contains("COLOR:")||item.contains("FONT-SIZE:")){ Log.i("Style Item: ", ""+item); newValue = newValue.concat(item).concat(";"); } } a.setValue(newValue); Log.i("New Atrrbute: ",""+newValue); } Log.i("FINAL HTML: ",""+e.outerHtml()); doc.html(e.outerHtml()); }
System.out.println(prefix +" Value : " + el.text()); for(Attribute attr : el.attributes()){ System.out.println(prefix + " " + attr.getKey() + " : " + attr.getValue());
sb.append('<').append(startTag.getName()); for (Attribute attribute : startTag.getAttributes()) { if (VALID_ATTRIBUTES.contains(attribute.getKey())) { sb.append(' ').append(attribute.getName()); if (attribute.getValue() != null) {