Jump to content

Web scraping: Difference between revisions

m (→‎{{header|Perl 6}}: need to match on content)
Line 39:
 
=={{header|8th}}==
<lang forth>\ Web-scrape sample: get UTC time from the US Naval Observatory:
<lang forth>( "http://tycho.usno.navy.mil/cgi-bin/timer.pl" net:get
: read-url \ -- s
if
<lang forth>( "http://tycho.usno.navy.mil/cgi-bin/timer.pl" net:get
>s
not if "Could not connect" throw then
/<BR>.*?(\d{2}:\d{2}:\d{2})\sUTC/
>s ;
tuck
 
r:match
: get-time
if
read-url
1 r:@
/<BR>.*?(\d{2}:\d{2}:\d{2})\sUTC/
nip
tuck r:match if
. cr
1 r:@ . cr
then ;
else
 
"Cannot connect. Error " . . cr
get-time bye
then
bye</lang>
) w:exec
bye</lang>
{{output}}
<pre>14:08:20</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.