Web scraping: Difference between revisions
Content added Content deleted
(added Ceylon) |
|||
Line 412: | Line 412: | ||
Mar. 29, 10:47:42 AM HAST |
Mar. 29, 10:47:42 AM HAST |
||
</pre> |
</pre> |
||
=={{header|Ceylon}}== |
|||
Don't forget to import ceylon.uri and ceylon.http.client in your module.ceylon file. |
|||
<lang ceylon>import ceylon.uri { |
|||
parse |
|||
} |
|||
import ceylon.http.client { |
|||
get |
|||
} |
|||
shared void run() { |
|||
// apparently the cgi link is deprecated? |
|||
value oldUri = "http://tycho.usno.navy.mil/cgi-bin/timer.pl"; |
|||
value newUri = "http://tycho.usno.navy.mil/timer.pl"; |
|||
value contents = downloadContents(newUri); |
|||
value time = extractTime(contents); |
|||
print(time else "nothing found"); |
|||
} |
|||
String downloadContents(String uriString) { |
|||
value uri = parse(uriString); |
|||
value request = get(uri); |
|||
value response = request.execute(); |
|||
return response.contents; |
|||
} |
|||
String? extractTime(String contents) => |
|||
contents |
|||
.lines |
|||
.filter((String element) => element.contains("UTC")) |
|||
.first |
|||
?.substring(4, 21);</lang> |
|||
=={{header|Clojure}}== |
=={{header|Clojure}}== |