I am writing something to extract product data from Amazon but I am not sure on how to normalize the whitespace in the HTML.
fn parse_html(html: std::string::String) {
let fragment = Html::parse_fragment(&html);
let product_title = Selector::parse(".s-line-clamp-2").unwrap();
for title in fragment.select(&product_title) {
let title_txt = title.text().collect::<Vec<_>>();
println!("{:?}", title_txt);
}
}
This works but the data i get is like this ["\n \n \n \n\n\n\n\n", "\n \n \n \n ", "Men\'s Sneakers", "\n \n \n \n \n", "\n\n \n"]
I only want this: ["Men\'s Sneakers"]