<예제 코드_1>
// cargo add select
use select::document::Document;
use select::predicate::Name;
fn main() {
let html = "<html><body><h1>Hello, world!</h1></body></html>";
let document = Document::from(html);
let h1 = document.find(Name("h1")).next().unwrap();
println!("{}", h1.text());
}
<예제 코드_2>
// cargo add scraper
use scraper::{Html, Selector};
fn main() {
let html = "<html><body><h1>Hello, World!</h1></body></html>";
let document = Html::parse_document(html);
let selector = Selector::parse("h1").unwrap();
let h1 = document.select(&selector).next().unwrap();
println!("{}", h1.text().collect::<Vec<_>>().join(""));
}
<참조 1> https://chat.openai.com
<참조 2>
'Rust' 카테고리의 다른 글
[Rust] fn main() -> Result<(), Box<dyn std::error::Error>> { } 가 무엇인가? (61일차) (0) | 2023.03.06 |
---|---|
[Rust] Scraping : Naver 메인 페이지 예제 (60일차) (0) | 2023.02.20 |
[Rust] Variable : Python 코드 비교 예제 (58일차) (0) | 2023.02.18 |
[Rust] Web Spider 예제 (57일차) (0) | 2023.02.12 |
댓글