Compare commits

..

No commits in common. "380ee66456b9876a378b9ce9a6b998766cfe69af" and "9a0098eb14a21beb77116fe23bb75486c745436d" have entirely different histories.

2 changed files with 18 additions and 24 deletions

View File

@ -1 +0,0 @@
# Scrape Stackoverflow for the word "pythonic" and see if it gets more average upvotes based on a claim from LowLevelLearning

View File

@ -8,19 +8,17 @@ struct Answer {
} }
// let's set up the sequence of steps we want the browser to take // let's set up the sequence of steps we want the browser to take
async fn get_answers(url: &str) -> Vec<Answer> { async fn get_answer() -> anyhow::Result<Answer> {
let c = ClientBuilder::native() let c = ClientBuilder::native()
.connect("http://localhost:4444") .connect("http://localhost:4444")
.await .await
.expect("failed to connect to WebDriver"); .expect("failed to connect to WebDriver");
// first, go to the Wikipedia page for Foobar // first, go to the Wikipedia page for Foobar
c.goto(url).await.unwrap(); c.goto("https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array").await?;
let answer_loc = c.find_all(Locator::Css(".answer")).await.unwrap(); let answer_loc = c.find(Locator::Css(".answer")).await;
let mut out_answers = vec![]; let text = answer_loc.unwrap().text().await.unwrap();
for answer in answer_loc {
let text = answer.text().await.unwrap();
let score = text let score = text
.clone() .clone()
@ -28,22 +26,19 @@ async fn get_answers(url: &str) -> Vec<Answer> {
.collect::<Vec<&str>>() .collect::<Vec<&str>>()
.get(0) .get(0)
.unwrap() .unwrap()
.parse::<u32>() .parse::<u32>()?;
.unwrap();
let content = text; let content = text;
out_answers.push(Answer { c.close().await.unwrap();
Ok(Answer {
upvotes: score, upvotes: score,
content, content,
author: "unimplemented".to_string(), author: "unimplemented".to_string(),
}); })
}
c.close().await.unwrap();
out_answers
} }
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
dbg!(get_answers("https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array").await); dbg!(get_answer().await);
} }