Administrator approval is now required for registering new accounts. If you are registering a new account, and are external to the University, please ask the repository owner to contact ServiceLine to request your account be approved. Repository owners must include the newly registered email address, and specific repository in the request for approval.

Verified Commit 377c0854 authored by Emily Rowlands's avatar Emily Rowlands
Browse files

Added Java version. Does not work atm

parent dcd12ecf
package jrr1g18.ecsnames;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ECSNames {
public static String getURLSource(URL url) throws IOException {
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
StringBuilder result = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
result.append(line);
}
return result.toString();
}
public static String getNameFromSource(String source) {
Pattern regex = Pattern.compile("(?:\"name\">).*(?:<\\/h1)");
Matcher matcher = regex.matcher(source);
String grp = matcher.group();
return grp.substring("\"name\"".length(), grp.length() - "<\\/h1".length());
}
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
String uid = stdin.nextLine();
stdin.close();
URL url = null;
try {
url = new URL("https://www.ecs.soton.ac.uk/people/".concat(uid));
} catch (MalformedURLException e) {
e.printStackTrace();
System.exit(1);
}
String source = "";
try {
source = getURLSource(url);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
String result = getNameFromSource(source);
System.out.println(result);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment