Web scraping: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: need to match on content)
Line 39: Line 39:


=={{header|8th}}==
=={{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
"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
then ;
else

"Cannot connect. Error " . . cr
get-time bye
then
</lang>
) w:exec
bye</lang>
{{output}}
{{output}}
<pre>14:08:20</pre>
<pre>14:08:20</pre>