2015-09-02 55 views
0
​​

這樣做的工作,顯示以下項目:Jsoup不會提取SRC ATTR

I/System.out﹕ <img width="650" height="400" src="http://www.somesite.net/wp-content/uploads/2015/09/11937978_482236235278145_7661294603539537192_o-650x400.jpg" class="attachment-small-thumb wp-post-image" alt="11937978_482236235278145_7661294603539537192_o-650x400"> 
09-02 20:43:31.191 2969-3005/net.android I/System.out﹕ <img width="650" height="400" src="http://www.somesite.net/wp-content/uploads/2015/09/Screenshot_16-650x400.jpg" class="attachment-small-thumb wp-post-image" alt="Screenshot_16-650x400"> 

我嘗試它包裹在for(Element e : els),檢索內部和外部的功能,它通過爲字符串,並使用System.out.print(stringname)

同時使用,

String absoluteUrl = els.absUrl("src"); //absolute URL on src 

String srcValue = els.attr("src"); 

,但它只是d沒有工作。我嘗試搜索Stackoverflow,但沒有類似的問題。

在此先感謝。

+2

請創建一個[MCVE](http://stackoverflow.com/help/mcve)。 – tachyonflux

回答

2

els是元素類型,即元素列表。只有元素有attr()方法。所以請嘗試:

Elements els = document.select("div.category3-image > a > img"); 
Element el = els.first(); 
System.out.print(el.attr("src")); 
+0

不打印任何東西。 – dinomuharemagic

+1

如果你提供你的觀察的例子,這真的會有幫助。如果沒有HTML源代碼,很難發現問題。 – luksch