I'm trying to scrape a webpage using the Select crate:
let document = Document::from_read(response).unwrap();
for node in document.find(Class("lia-list-row")) {
let title = node.find(Class("page-link")).next().unwrap();
let title_text = title.text().trim();
println!("{}\n", title_text);
}
Which results in following error:
let title_text = title.text().trim();
^^^^^^^^^^^^ - temporary value is freed at the end of this statement
|
creates a temporary which is freed while still in use
println!("{} - {}\n", i, title_text);
---------- borrow used here, in later iteration of loop
I solved it by separating the .text()
and .trim()
let title_text = title.text();
let trim_text = title_text.trim();
What is the difference? Why did the first attempt fail?