From 0239b0eb9ea0a3b214bbdcd12910b37b74d6eb35 Mon Sep 17 00:00:00 2001 From: ww2g23 <ww2g23@soton.ac.uk> Date: Sat, 7 Oct 2023 00:12:31 +0000 Subject: [PATCH] Uploaded Project --- EmailToName.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 EmailToName.java diff --git a/EmailToName.java b/EmailToName.java new file mode 100644 index 0000000..014e4e5 --- /dev/null +++ b/EmailToName.java @@ -0,0 +1,46 @@ +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.net.*; + +public class EmailToName{ + public static void main(String[] args){ + + try{ + + //Get email id from the user + System.out.println("Please enter the email id of the name you want"); + BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in)); + String emailID = userIn.readLine(); + + System.out.println("Fetching..."); + + URL test = new URL("https://www.ecs.soton.ac.uk/people/"+emailID); + + //creates the website reader from URL reader + URLConnection connection = test.openConnection(); + InputStream stream = connection.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); + + Pattern titlePattern = Pattern.compile("property=\"og:title\" content=\"(.*)\" />"); + + Matcher matcher; + String line; + do { + line = reader.readLine(); + matcher = titlePattern.matcher(line); + + } while (!matcher.find()); + + System.out.println("Their name is:"); + System.out.println(matcher.group(1)); + + } + catch(Exception e){ + System.out.println("Error!"); + System.out.println(e); + } + } +} \ No newline at end of file -- GitLab