cheesebot/ocaml/simpleHttp.ml
2014-03-01 22:32:28 +01:00

38 lines
815 B
OCaml

open Printf
open Http_client
open Https_client
open Nethtml;;
Ssl.init();
Convenience.configure_pipeline
(fun p ->
let ctx = Ssl.create_context Ssl.TLSv1 Ssl.Client_context in
let tct = https_transport_channel_type ctx in
p # configure_transport https_cb_id tct
)
let extract_string_value document =
match document with
| Data(s) -> s
| _ -> ""
let rec get_title_element document =
match document with
| Element(e, args, sub) -> printf "%s: %s" "Element\n" e
| Data(s) -> printf "%s: %s" "Data\n" s
let get_http_title body =
let ch = new Netchannels.input_string body in
let doc = Nethtml.parse ch in
get_title_element (List.hd doc)
(* TODO: Log errors *)
let get_body url =
try Convenience.http_get url with
| Http_error e -> "http error /o\\"
| Failure f -> "http fail lol"