Created
March 9, 2015 11:12
-
-
Save revox/37a930146a26de125189 to your computer and use it in GitHub Desktop.
JSoup using abs:href to get absolute URLs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.jsoup.Jsoup; | |
| import org.jsoup.nodes.Document; | |
| import org.jsoup.nodes.Element; | |
| import org.jsoup.select.Elements; | |
| import java.io.IOException; | |
| public class JSoupExampleThree { | |
| public static void main(String[] args) throws Exception { | |
| Document doc = Jsoup.connect("http://gold.ac.uk").get(); | |
| Elements links = doc.getElementsByTag("a"); | |
| String relHref = links.get(1).attr("href"); // == "/" | |
| System.out.println(relHref); | |
| String absHref = links.get(1).attr("abs:href"); // "http://jsoup.org/" | |
| System.out.println(absHref); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment