Scraper crate help. Basic example

Hi, new around here.

This could be a very basic question, but I am a newbie in rust. I want to use [scraper]( crate and I would love to know if you guys have way to print the first example. I don't fully understand what to do with the parsed document. Here is the example

use scraper::Html;

let html = r#"
    <!DOCTYPE html>
    <meta charset="utf-8">
    <title>Hello, world!</title>
    <h1 class="foo">Hello, <i>world!</i></h1>

let document = Html::parse_document(html);

I just want to print the tags that we have on that string.

Thanks for the support.

scraper is primarily aimed at letting you parse a known page by applying CSS selectors. If you just want to walk the parsed HTML though you can use the tree field on HTML.

Thanks for the reply. I found that println!("{:#?}", document)! works for this. The next step is passing that to a JSON format. I will be looking a the tree field tho. Thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.