ff69981a5c
Use ocamlbuild command to build cheesebot.
42 lines
973 B
OCaml
42 lines
973 B
OCaml
open Str
|
|
open String
|
|
open Printf
|
|
open Ssl
|
|
open Http_client.Convenience
|
|
open Https_client
|
|
open Nethtml
|
|
open Netchannels;;
|
|
|
|
Ssl.init();
|
|
Http_client.Convenience.configure_pipeline
|
|
(fun p ->
|
|
let ctx = Ssl.create_context Ssl.TLSv1 Ssl.Client_context in
|
|
let tct = Https_client.https_transport_channel_type ctx in
|
|
p # configure_transport Http_client.https_cb_id tct
|
|
)
|
|
|
|
|
|
let extract_string_value document =
|
|
match document with
|
|
| Nethtml.Data(s) -> s
|
|
| _ -> ""
|
|
|
|
|
|
let rec get_title_element document =
|
|
match document with
|
|
| Nethtml.Element(e, args, sub) -> Printf.printf "%s: %s" "Element\n" e
|
|
| Nethtml.Data(s) -> Printf.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 Http_client.Convenience.http_get url with
|
|
| Http_client.Http_error e -> "http error /o\\"
|
|
| Failure f -> "http fail lol"
|