0

ok so im using Jsoup to get the link for an image from this piece of code

<div id="section_1" class="story  inview" bgimage="AAA" style="width: 1366px; height: 853.75px; background-image: url(http://Fake.link.comm);" scrollto="0">

and the code that i'm using is this

Document doc = Jsoup.connect(web).get();
Element content = doc.getElementById("section_1");
Elements elements = doc.getElementsByClass(content.className());
for( Element e : elements ) {
          String attr = e.attr("style");
          System.out.println( attr.substring( attr.indexOf("http://"), attr.indexOf(")") ) );
        }

however it gives me back an out of index error with -1 value after some looking into it i realized for some reason the code that the parser reads is this

<div id="section_1" class="story" bgimage="AAA"> 

and as such there is no "style" attribute.... can someone tell me why it is behaving like this? many thanks!

4

1 回答 1

1

如果您会使用它content而不是e它会起作用。

      String attr = content.attr("style");
      System.out.println( attr.substring( attr.indexOf("http://"), attr.indexOf(")") ) );

你刚刚dive.

于 2013-01-20T18:25:13.663 回答