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
|
||||
async fn get_answer() -> anyhow::Result<Answer> {
|
||||
async fn get_answers() -> Vec<Answer> {
|
||||
let c = ClientBuilder::native()
|
||||
.connect("http://localhost:4444")
|
||||
.await
|
||||
.expect("failed to connect to WebDriver");
|
||||
|
||||
// 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 text = answer_loc.unwrap().text().await.unwrap();
|
||||
let answer_loc = c.find_all(Locator::Css(".answer")).await.unwrap();
|
||||
let mut out_answers = vec![];
|
||||
for answer in answer_loc {
|
||||
let text = answer.text().await.unwrap();
|
||||
|
||||
let score = text
|
||||
.clone()
|
||||
.split('\n')
|
||||
.collect::<Vec<&str>>()
|
||||
.get(0)
|
||||
.unwrap()
|
||||
.parse::<u32>()?;
|
||||
let content = text;
|
||||
let score = text
|
||||
.clone()
|
||||
.split('\n')
|
||||
.collect::<Vec<&str>>()
|
||||
.get(0)
|
||||
.unwrap()
|
||||
.parse::<u32>()
|
||||
.unwrap();
|
||||
let content = text;
|
||||
|
||||
out_answers.push(Answer {
|
||||
upvotes: score,
|
||||
content,
|
||||
author: "unimplemented".to_string(),
|
||||
});
|
||||
}
|
||||
c.close().await.unwrap();
|
||||
|
||||
Ok(Answer {
|
||||
upvotes: score,
|
||||
content,
|
||||
author: "unimplemented".to_string(),
|
||||
})
|
||||
out_answers
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dbg!(get_answer().await);
|
||||
dbg!(get_answers().await);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user