2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -9,13 +9,15 @@
|
|||
{{omit from|PostScript|no network access}}
|
||||
{{omit from|Retro|Does not have network access.}}
|
||||
{{omit from|ZX Spectrum Basic|Does not have network access.}}
|
||||
Create a program that downloads the time from this URL: [http://tycho.usno.navy.mil/cgi-bin/timer.pl http://tycho.usno.navy.mil/cgi-bin/timer.pl] and then prints the current UTC time by extracting just the UTC time from the web page's [[HTML]].
|
||||
|
||||
;Task:
|
||||
Create a program that downloads the time from this URL: [http://tycho.usno.navy.mil/cgi-bin/timer.pl http://tycho.usno.navy.mil/cgi-bin/timer.pl] and then prints the current UTC time by extracting just the UTC time from the web page's [[HTML]].
|
||||
|
||||
<!-- As of March 2014, the page is available
|
||||
{{task|Networking and Web Interaction}}
|
||||
|
||||
The page http://tycho.usno.navy.mil/cgi-bin/timer.pl is no longer available since july 2011. The relevant part of that page source looked like this:
|
||||
|
||||
The page http://tycho.usno.navy.mil/cgi-bin/timer.pl is no longer available since July 2011.
|
||||
The relevant part of that page source looked like this:
|
||||
<pre>
|
||||
...
|
||||
|
||||
|
|
@ -31,6 +33,7 @@ The page http://tycho.usno.navy.mil/cgi-bin/timer.pl is no longer available sinc
|
|||
|
||||
...
|
||||
</pre>
|
||||
|
||||
End of comment -->
|
||||
|
||||
If possible, only use libraries that come at no ''extra'' monetary cost with the programming language and that are widely available and popular such as [http://www.cpan.org/ CPAN] for Perl or [[Boost]] for C++.
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ function getusnotime()
|
|||
@sprintf "get(%s)\n => %s" url err
|
||||
end
|
||||
isa(s, Requests.Response) || return (s, false)
|
||||
t = match(r"<BR>(.*UTC)", s.data)
|
||||
isa(t, RegexMatch) || return (@sprintf("raw html:\n %s", s.data), false)
|
||||
return (t.captures[1], true)
|
||||
t = match(r"(?<=<BR>)(.*?UTC)", readall(s))
|
||||
isa(t, RegexMatch) || return (@sprintf("raw html:\n %s", readall(s)), false)
|
||||
return (t.match, true)
|
||||
end
|
||||
|
||||
(t, issuccess) = getusnotime()
|
||||
(t, issuccess) = getusnotime();
|
||||
|
||||
if issuccess
|
||||
println("The USNO time is ", t)
|
||||
|
|
|
|||
14
Task/Web-scraping/Lua/web-scraping.lua
Normal file
14
Task/Web-scraping/Lua/web-scraping.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
local http = require("socket.http") -- Debian package is 'lua-socket'
|
||||
|
||||
function scrapeTime (pageAddress, timeZone)
|
||||
local page = http.request(pageAddress)
|
||||
if not page then return "Cannot connect" end
|
||||
for line in page:gmatch("[^<BR>]*") do
|
||||
if line:match(timeZone) then
|
||||
return line:match("%d+:%d+:%d+")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local url = "http://tycho.usno.navy.mil/cgi-bin/timer.pl"
|
||||
print(scrapeTime(url, "UTC"))
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
use HTTP::Client; # https://github.com/supernovus/perl6-http-client/
|
||||
my $site = "http://tycho.usno.navy.mil/cgi-bin/timer.pl";
|
||||
HTTP::Client.new.get($site).match(/'<BR>'( .+? <ws> UTC )/)[0].say
|
||||
HTTP::Client.new.get($site).content.match(/'<BR>'( .+? <ws> UTC )/)[0].say
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@(next `!wget -c http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2> /dev/null`)
|
||||
@(next @(open-command "wget -c http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2> /dev/null"))
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final"//EN>
|
||||
<html>
|
||||
<body>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
@(next `!wget -c http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2> /dev/null`)
|
||||
@(next @(open-command "wget -c http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2> /dev/null"))
|
||||
@(skip)
|
||||
<BR>@time@\ UTC@(skip)
|
||||
@(output)
|
||||
|
|
|
|||
2
Task/Web-scraping/Tcl/web-scraping-2.tcl
Normal file
2
Task/Web-scraping/Tcl/web-scraping-2.tcl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
set data [exec curl -s http://tycho.usno.navy.mil/cgi-bin/timer.pl]
|
||||
puts [lrange [lsearch -glob -inline [split $data <BR>] *UTC*] 0 3]
|
||||
3
Task/Web-scraping/UNIX-Shell/web-scraping-2.sh
Normal file
3
Task/Web-scraping/UNIX-Shell/web-scraping-2.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/tcsh -f
|
||||
set page = `wget -q -O- "http://tycho.usno.navy.mil/cgi-bin/timer.pl"`
|
||||
echo `awk -v s="${page[22]}" 'BEGIN{print substr(s,5,length(s))}'` ${page[23]} ${page[24]}
|
||||
Loading…
Add table
Add a link
Reference in a new issue