RosettaCodeData/Task/Web-scraping/Julia/web-scraping-1.julia

23 lines
557 B
Text
Raw Permalink Normal View History

2020-02-17 23:21:07 -08:00
using Requests, Printf
2015-11-18 06:14:39 +00:00
function getusnotime()
const url = "http://tycho.usno.navy.mil/timer.pl"
s = try
get(url)
catch err
@sprintf "get(%s)\n => %s" url err
end
isa(s, Requests.Response) || return (s, false)
2018-06-22 20:57:24 +00:00
t = match(r"(?<=<BR>)(.*?UTC)", readstring(s))
isa(t, RegexMatch) || return (@sprintf("raw html:\n %s", readstring(s)), false)
2016-12-05 22:15:40 +01:00
return (t.match, true)
2015-11-18 06:14:39 +00:00
end
2016-12-05 22:15:40 +01:00
(t, issuccess) = getusnotime();
2015-11-18 06:14:39 +00:00
if issuccess
println("The USNO time is ", t)
else
println("Failed to fetch UNSO time:\n", t)
end