■ HTML 문자열을 파싱하는 방법을 보여준다.
▶ Cargo.toml
1 2 3 4 5 6 7 8 9 |
[package] name = "test_project" version = "0.1.0" edition = "2021" [dependencies] scraper = "0.12" |
▶ src/main.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
use scraper; fn main() { let html_string : &str = "<html><body><p>테스트 문자열 1</p><p>테스트 문자열 1</p></body></html>"; let html : scraper::Html = scraper::Html::parse_document(&html_string); let selector : scraper::Selector = scraper::Selector::parse("p").unwrap(); for (index, element) in html.select(&selector).enumerate() { println!("{} : {:?}", index, element.value()); } } |