From 857a81478a4d2c0163aeb8de1dc26db0b513266c Mon Sep 17 00:00:00 2001 From: spv Date: Sat, 24 Aug 2024 14:26:21 +0200 Subject: [PATCH] switched over to matching for css selector --- src/main.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index d18dd8c..ebeb9d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,15 @@ -use fantoccini::{ClientBuilder, Locator}; +use fantoccini::{elements::Element, ClientBuilder, Locator}; + +const MAX_ANSWER_INDEX: u128 = 100000000; + +struct Answer { + upvotes: u32, + author: String, + content: String, +} // let's set up the sequence of steps we want the browser to take -#[tokio::main] -async fn main() -> Result<(), fantoccini::error::CmdError> { +async fn get_answer() -> anyhow::Result { let c = ClientBuilder::native() .connect("http://localhost:4444") .await @@ -11,9 +18,13 @@ async fn main() -> Result<(), fantoccini::error::CmdError> { // first, go to the Wikipedia page for Foobar c.goto("https://stackoverflow.com/questions/78872368/how-to-set-up-webpack-devserver-config-to-build-another-target").await?; - // click "Foo (disambiguation)" - let answer_loc = c.find(Locator::Id("answer-.*")).await?; - dbg!(answer_loc); + let answer_loc = c.find(Locator::Css("answer")).await; - c.close().await + c.close().await; + Ok(answer_loc?) +} + +#[tokio::main] +async fn main() { + dbg!(get_answer().await); }