cheesebot/ocaml/simpleHttp.ml

38 lines
815 B
OCaml
Raw Normal View History

open Printf
2014-03-01 22:32:28 +01:00
open Http_client
open Https_client
2014-03-01 22:32:28 +01:00
open Nethtml;;
Ssl.init();
2014-03-01 22:32:28 +01:00
Convenience.configure_pipeline
(fun p ->
let ctx = Ssl.create_context Ssl.TLSv1 Ssl.Client_context in
2014-03-01 22:32:28 +01:00
let tct = https_transport_channel_type ctx in
p # configure_transport https_cb_id tct
)
let extract_string_value document =
match document with
2014-03-01 22:32:28 +01:00
| Data(s) -> s
| _ -> ""
let rec get_title_element document =
match document with
2014-03-01 22:32:28 +01:00
| 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 =
2014-03-01 22:32:28 +01:00
try Convenience.http_get url with
| Http_error e -> "http error /o\\"
| Failure f -> "http fail lol"