There is an html line:

<p style="text-align: justify;"> <a href="http://www.postfactum.ks.ua/wp-content/uploads/2015/06/DSC_0320_1.jpg" rel="" style="" target="" title=""> <img alt="DSC_0320_1" class="alignleft size-medium wp-image-89182" height="163" src="http://www.postfactum.ks.ua/wp-content/uploads/2015/06/DSC_0320_1-300x163.jpg" style="" title="title»" width="300" /> </a> <span style="font-size:14px;"> </p> 

You need to get the address of the image: http://www.postfactum.ks.ua/wp-content/uploads/2015/06/DSC_0320_1-300x163.jpg . Trying to parse:

 Document doc = Jsoup.parse(image_url); if (doc.select("img[src]").size() > 0) { Element image = doc.select("img[src]").get(0); } else { image_url = "null"; } 

There are no errors, but the string is empty. What could be the problem?

    1 answer 1

    First, you need to use the first () or last () method depending on the order of the element. In your case, you need to use the first () method. Element image = doc.select("img[src]").first(); . Second, you did not specify the "src" attribute: image_url = image.attr("src"); . Full code:

      Document doc = Jsoup.parse(mage_url); if (doc.select("img[src]").size() > 0) { Element image = doc.select("img[src]").first(); image_url = image.attr("src"); } else { image_url = "null"; } 
    • Thank you) Rescued. - Ruslan Chepizhko