Web scraping: Difference between revisions

Content added Content deleted
Line 982: Line 982:
I'm using the <code>Requests.jl</code> package for this solution. Note, I used a slightly different URL after finding that the one specified in the task description is deprecated (though it still works).
I'm using the <code>Requests.jl</code> package for this solution. Note, I used a slightly different URL after finding that the one specified in the task description is deprecated (though it still works).
<lang Julia>using Requests
<lang Julia>using Requests

function getusnotime()
function getusnotime()
const url = "http://tycho.usno.navy.mil/timer.pl"
const url = "http://tycho.usno.navy.mil/timer.pl"
Line 991: Line 991:
end
end
isa(s, Requests.Response) || return (s, false)
isa(s, Requests.Response) || return (s, false)
t = match(r"(?<=<BR>)(.*UTC)", readall(s))
t = match(r"(?<=<BR>)(.*?UTC)", readall(s))
isa(t, RegexMatch) || return (println("raw html:\n", readall(s)), false)
isa(t, RegexMatch) || return (@sprintf("raw html:\n %s", readall(s)), false)
return (t.match, true)
return (t.match, true)
end
end

(t, issuccess) = getusnotime()
(t, issuccess) = getusnotime()

if issuccess
if issuccess
println("The USNO time is ", t)
println("The USNO time is ", t)