diff --git a/bin/twitter.ml b/bin/twitter.ml index 9dd9b4f..ac57cbe 100644 --- a/bin/twitter.ml +++ b/bin/twitter.ml @@ -95,6 +95,11 @@ let go_to_profile ctx = then raise (Any "Too many profile button found") else List.nth l 0 in - click ctx.session_id profile_button; - Unix.sleep 4 + ignore + (navigate + ctx.session_id + (fmt "https://twitter.com%s/with_replies" (get_url ctx.session_id profile_button))); + Unix.sleep 2 ;; + +let find_latest_tweet = () diff --git a/lib/net.ml b/lib/net.ml index c034d46..b833168 100644 --- a/lib/net.ml +++ b/lib/net.ml @@ -128,3 +128,16 @@ let click session_id element_id = (fmt "%s/element/%s/click" (driver session_id) element_id) Json.empty) ;; + +let get_url session_id button_id = + let response = + execute_get_request (fmt "%s/element/%s/attribute/href" (driver session_id) button_id) + in + match Yojson.Safe.from_string response with + | `Assoc fields -> + (match List.assoc "value" fields with + | `String href -> href + | _ as e -> + raise (Any (fmt "Unexpected response from driver: %s" (Yojson.Safe.to_string e)))) + | _ -> raise (Any "get_url | Invalid JSON") +;;