array of answers returned for url now
This commit is contained in:
parent
9a0098eb14
commit
fde73fc57b
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Scrape Stackoverflow for the word "pythonic" and see if it gets more average upvotes based on a claim from LowLevelLearning
|
41
src/main.rs
41
src/main.rs
@ -8,37 +8,42 @@ 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_answer() -> anyhow::Result<Answer> {
|
async fn get_answers() -> Vec<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("https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array").await?;
|
c.goto("https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-processing-an-unsorted-array").await.unwrap();
|
||||||
|
|
||||||
let answer_loc = c.find(Locator::Css(".answer")).await;
|
let answer_loc = c.find_all(Locator::Css(".answer")).await.unwrap();
|
||||||
let text = answer_loc.unwrap().text().await.unwrap();
|
let mut out_answers = vec![];
|
||||||
|
for answer in answer_loc {
|
||||||
|
let text = answer.text().await.unwrap();
|
||||||
|
|
||||||
let score = text
|
let score = text
|
||||||
.clone()
|
.clone()
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.get(0)
|
.get(0)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.parse::<u32>()?;
|
.parse::<u32>()
|
||||||
let content = text;
|
.unwrap();
|
||||||
|
let content = text;
|
||||||
|
|
||||||
|
out_answers.push(Answer {
|
||||||
|
upvotes: score,
|
||||||
|
content,
|
||||||
|
author: "unimplemented".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
c.close().await.unwrap();
|
c.close().await.unwrap();
|
||||||
|
|
||||||
Ok(Answer {
|
out_answers
|
||||||
upvotes: score,
|
|
||||||
content,
|
|
||||||
author: "unimplemented".to_string(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
dbg!(get_answer().await);
|
dbg!(get_answers().await);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user