Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this using a fullworthy HTML parser like <a href="http://jsoup.org/" rel="nofollow noreferrer">Jsoup</a>. There's a <a href="http://jsoup.org/apidocs/org/jsoup/nodes/Node.html#absUrl%28java.lang.String%29" rel="nofollow noreferrer"><code>Node#absUrl()</code></a> which does exactly what you want.</p> <pre><code>package com.stackoverflow.q3394298; import java.net.URL; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; public class Test { public static void main(String... args) throws Exception { URL url = new URL("https://stackoverflow.com/questions/3394298/"); Document document = Jsoup.connect(url).get(); Element link = document.select("a.question-hyperlink").first(); System.out.println(link.attr("href")); System.out.println(link.absUrl("href")); } } </code></pre> <p>which prints (correctly) the following for the title link of your current question:</p> <pre> /questions/3394298/full-link-extraction-using-java https://stackoverflow.com/questions/3394298/full-link-extraction-using-java </pre> <p>Jsoup may have more other (undiscovered) advantages for your purpose as well.</p> <h3>Related questions:</h3> <ul> <li><a href="https://stackoverflow.com/questions/3152138/what-are-the-pros-and-cons-of-the-leading-java-html-parsers">What are the pros and cons of the leading HTML parsers in Java?</a></li> </ul> <hr> <p><strong>Update</strong>: if you want to select <em>all</em> links in the document, then do as follows:</p> <pre><code> Elements links = document.select("a"); for (Element link : links) { System.out.println(link.attr("href")); System.out.println(link.absUrl("href")); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload