There is a page with this code:

<div class="team" style="float: right; background: url('//site.com/img/teams/CPW.jpg?1452774441')"></div> 

How can I pull a picture and then insert it into the GridView? So I tried to do something, but I think this is the wrong approach.

 Elements teamPics = doc.select("background|url"); 
  • It seems to me that this cannot be done with select . - Vladyslav Matviienko
  • And what advise? - AlexS
  • 2
    choose select whole style, and using regular expressions - rip out the background url from the style already - Vladyslav Matviienko
  • How can this be done? - AlexS
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

select the entire style with the select, and using regular expressions, rip out the background url from the style

 String html = "<div class=\"team\" style=\"float: right; background: url('//site.com/img/teams/CPW.jpg?1452774441')\"></div>"; Document doc = Jsoup.parse(html); String slyle = doc.select("div").attr("style"); Pattern pattern = Pattern.compile(Pattern.quote("url('") + "(.*?)" + Pattern.quote("'")); Matcher matcher = pattern.matcher(slyle); if (matcher.find()) { Log.d("TAG", matcher.group(1)); // //site.com/img/teams/CPW.jpg?1452774441 } 
  • And if on the page there are several pictures of the type (//site.com/img/teams/*.jpg) then what can I do? - AlexS
  • @AlexSuvorov, probably something like this for (Element div : doc.select("div")) { String slyle = div.attr("style"); ... } for (Element div : doc.select("div")) { String slyle = div.attr("style"); ... } - katso
  • pancake. elementary. I'm all attached to the link ( - AlexS