SukruK SukruK - 3 months ago 26
Java Question

how to get image using html parsing with jsoup

I want get all images using html parsing with jsoup.
I use below code ;

Elements images ="img[src~=(?i)\\.(jpe?g)]");
for (Element image : images) {

//System.out.println("\nsrc : " + image.attr("src"));


I parse this method all images but i want to parse this url

I want to parse beginnig of this url .... .jpg

How to get parse like this ?


This will probably give you what you ask for, though your question is a bit unclear, so I can't be sure.

public static void main(String args[]){

    Document doc = null;
    String url = "";
    try {
        doc = Jsoup.connect(url).get();
    } catch (IOException e1) {

    for (Element e :"img[src~=(?i)\\.(jpe?g)]")) {

So, this might not be a very "clean" solution, but the if-statement will make sure it only prints out the image URL's from the /images/-directory on the server.