import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.io.FileReader;
public class Main {
public static void main(String[] args
try this:
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://www.yahoo.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);// or save to some StringBuilder like this: sb.append(inputLine); then pass the sb.toString() to the method that gets links out of it - > see getLinks below
in.close();
}
}
private static final String CLOSING_QUOTE = "\"";
private static final String HREF_PREFIX = "href=\"";
private static final String HTTP_PREFIX = "http://";
public static Set getLinks(String page) {
Set links = new HashSet();
String[] rawLinks = StringUtils.splitByWholeSeparator(page, HREF_PREFIX);
for (String str : rawLinks) {
if(str.startsWith(HTTP_PREFIX)) {
links.add(StringUtils.substringBefore(str, CLOSING_QUOTE));
}
}
return links;
}