Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
Week 2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jrr1g18-space-cadets
Week 2
Commits
377c0854
Verified
Commit
377c0854
authored
6 years ago
by
Emily Rowlands
Browse files
Options
Downloads
Patches
Plain Diff
Added Java version. Does not work atm
parent
dcd12ecf
Branches
main
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
wk1/java/src/jrr1g18/ecsnames/ECSNames.java
+61
-0
61 additions, 0 deletions
wk1/java/src/jrr1g18/ecsnames/ECSNames.java
with
61 additions
and
0 deletions
wk1/java/src/jrr1g18/ecsnames/ECSNames.java
0 → 100644
+
61
−
0
View file @
377c0854
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
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment