How to resolve relative URL with Jsoup?

Hi, I have a problem with Jsoup.

I clear the page and get a lot of URLs. Some of them relate to the relative the URL: "../index.php", "../admin", "../details.php".

I use attr("abs:href")to get the absolute url, but these links appear aswww.domain.com/../admin.php

I would like to know if this is a mistake.

Is there a way to get the real absolute path using jsoup? how can i solve this?

I also tried with absurl("href")but did not work.

+5
source share
2 answers

also a good option is to use the abs: href or abs: src attributes:

String relHref = link.attr("href"); // == "/"
String absHref = link.attr("abs:href"); // "http://jsoup.org/"

it is also described there: http://jsoup.org/cookbook/extracting-data/working-with-urls

+10
source

element , : element.absUrl("href").

URI (, setBaseUri("http://www.myexample.com")) Document element).

shure Uri !

:

element.setBaseUri("http://www.example.com/abc/");
element.attr("href", "../b/here");

: http://www.example.com/b/here

:

element.setBaseUri("http://www.example.com/abc/");
element.attr("href", "../../b/here");

: http://www.example.com/../b/here

- > , uri!

+9

All Articles