Use el ejemplo de:
[URL="http://chuwiki.chuidiang.org/index.php?title=Extraer_enlaces_de_una_URL_con_Jav a"]http://chuwiki.chuidiang.org/index.php?title=Extraer_enlaces_de_una_URL_con_Jav a[/URL]
Código:
Con algunas páginas funciona y con otras no, en este caso no da errores pero tampoco muestra nada. public class ExtractLinksFromUrl { public static void main(String[] args) throws Exception { String content = extractContent("https://www.taringa.net/post/humor/19461893/Imagenes-divertidas-para-acortar-la-semana.html"); showLinks(content); } private static String extractContent(String urlString)throws MalformedURLException, IOException { URL url = new URL(urlString); URLConnection urlConnection = url.openConnection(); InputStream is = urlConnection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String content = ""; String linea = br.readLine(); while((linea = br.readLine())!=null){ content+=linea; linea = br.readLine(); } br.close(); return content; } private static void showLinks(String content) { Pattern pattern = Pattern.compile("(?i)HREF\\s*=\\s*\"(.*?)\""); Matcher matcher = pattern.matcher(content); while (matcher.find()) { System.out.println(matcher.group(1)); } }