navigate to twitter

This commit is contained in:
Mylloon 2023-05-13 16:17:18 +02:00
parent 033d750400
commit a10ca91700
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 20 additions and 5 deletions

View file

@ -13,7 +13,10 @@ let stop (driver_process, session_id) =
stop_process driver_process
;;
let main session_id = print_endline session_id
let main session_id =
let body = navigate "https://twitter.com/i/flow/login" session_id in
print_endline body
;;
let () =
let data = start (Gecko "0.33.0") in

View file

@ -11,17 +11,25 @@ let send_post_request url json =
(fun (_response, body) -> Cohttp_lwt.Body.to_string body)
;;
let send_get_request url =
Lwt.bind
(Client.get (Uri.of_string url))
(fun (_response, body) -> Cohttp_lwt.Body.to_string body)
;;
let send_delete_request url =
Lwt.bind
(Client.delete (Uri.of_string url))
(fun (_response, body) -> Cohttp_lwt.Body.to_string body)
;;
let execute_request url json = Lwt_main.run (send_post_request url json)
let execute_post_request url json = Lwt_main.run (send_post_request url json)
let execute_get_request url = Lwt_main.run (send_get_request url)
let execute_delete_request url = Lwt_main.run (send_delete_request url)
(* Server MUST be started already *)
let get_session () =
let response = execute_request (fmt "%s" driver_url) Json.connection_payload in
let response = execute_post_request (fmt "%s" driver_url) Json.connection_payload in
match Yojson.Safe.from_string response with
| `Assoc fields ->
let value = List.assoc "value" fields in
@ -35,9 +43,13 @@ let get_session () =
;;
let close_session id =
Lwt_main.run (send_delete_request (fmt "%s/%s" driver_url id)) = "{\"value\":null}"
execute_delete_request (fmt "%s/%s" driver_url id) = "{\"value\":null}"
;;
let navigate url session_id =
execute_request (fmt "%s/%s/url" driver_url session_id) (Json.navigate_payload url)
ignore
(execute_post_request
(fmt "%s/%s/url" driver_url session_id)
(Json.navigate_payload url));
execute_get_request (fmt "%s/%s/title" driver_url session_id)
;;