Navigate to tweet and replies instead of only the profile

This commit is contained in:
Mylloon 2023-05-15 12:11:59 +02:00
parent 408a2b0845
commit d0b739acf8
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 20 additions and 2 deletions

View file

@ -95,6 +95,11 @@ let go_to_profile ctx =
then raise (Any "Too many profile button found") then raise (Any "Too many profile button found")
else List.nth l 0 else List.nth l 0
in in
click ctx.session_id profile_button; ignore
Unix.sleep 4 (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 = ()

View file

@ -128,3 +128,16 @@ let click session_id element_id =
(fmt "%s/element/%s/click" (driver session_id) element_id) (fmt "%s/element/%s/click" (driver session_id) element_id)
Json.empty) 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")
;;