Jump to content

Web scraping: Difference between revisions

Updated to work with Nim 1.4: added "newHttpClient". Changed code to work with Rosetta page as the original URL no longer works. Added output.
(added Rust programming solution)
(Updated to work with Nim 1.4: added "newHttpClient". Changed code to work with Rosetta page as the original URL no longer works. Added output.)
Line 1,359:
 
=={{header|Nim}}==
Using Rosetta Talk page URL.
<lang nim>import httpclient, strutils
 
var client = newHttpClient()
for line in getContent("http://tycho.usno.navy.mil/cgi-bin/timer.pl").splitLines:
 
if " UTC" in line:
var res: string
echo line[4..line.high]</lang>
for line in client.getContent("httphttps://tychorosettacode.usno.navy.milorg/cgi-binwiki/timer.plTalk:Web_scraping").splitLines:
let k = line.find("UTC")
if k >= 0:
res = line[0..(k - 3)]
let k = res.rfind("</a>")
res = res[(k + 6)..^1]
break
echo if res.len > 0: res else: "No date/time found."</lang>
 
{{out}}
<pre>20:59, 30 May 2020</pre>
 
=={{header|Objeck}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.