SukruK SukruK - 1 year ago 139
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 ?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download