HTML parsing and querying with CSS selectors.
fast_scraper
is on Crates.io and GitHub.
Scraper provides an interface to Servo's html5ever
and selectors
crates, for browser-grade
parsing and querying.
```rust use fast_scraper::Html;
let html = r#"
let document = Html::parse_document(html); ```
rust
use fast_scraper::Html;
let fragment = Html::parse_fragment("<h1>Hello, <i>world!</i></h1>");
rust
use fast_scraper::Selector;
let selector = Selector::parse("h1.foo").unwrap();
```rust use fast_scraper::{Html, Selector};
let html = r#"
let fragment = Html::parse_fragment(html); let selector = Selector::parse("li").unwrap();
for element in fragment.select(&selector) { assert_eq!("li", element.value().name()); } ```
```rust use fast_scraper::{Html, Selector};
let html = r#"
let fragment = Html::parsefragment(html); let ulselector = Selector::parse("ul").unwrap(); let li_selector = Selector::parse("li").unwrap();
let ul = fragment.select(&ulselector).next().unwrap(); for element in ul.select(&liselector) { assert_eq!("li", element.value().name()); } ```
```rust use fast_scraper::{Html, Selector};
let fragment = Html::parse_fragment(r#""#); let selector = Selector::parse(r#"input[name="foo"]"#).unwrap();
let input = fragment.select(&selector).next().unwrap(); assert_eq!(Some("bar"), input.value().attr("value")); ```
```rust use fast_scraper::{Html, Selector};
let fragment = Html::parse_fragment("
let h1 = fragment.select(&selector).next().unwrap();
asserteq!("Hello, world!
", h1.html());
asserteq!("Hello, world!", h1.inner_html());
```
```rust use fast_scraper::{Html, Selector};
let fragment = Html::parse_fragment("
let h1 = fragment.select(&selector).next().unwrap();
let text = h1.text().collect::
assert_eq!(vec!["Hello, ", "world!"], text); ```
Please feel free to open pull requests. If you're planning on implementing something big (i.e. not fixing a typo, a small bug fix, minor refactor, etc) then please open an issue first.