causal-agent / scraper

HTML parsing and querying with CSS selectors
https://docs.rs/scraper
ISC License
1.81k stars 100 forks source link

no method named `next_sibling_element` found for struct `ElementRef<'_>` in the current scope #106

Closed thelastfantasy closed 1 year ago

thelastfantasy commented 1 year ago
use reqwest::Client;
use scraper::{Html, Selector};
use selectors::Element;

let url = "https://www.kansou.me/";
let client = Client::new();
let res = client.get(url).send().await?;

if !res.status().is_success() {
    return Err(Box::new(ScraperResult::Error(
        res.status().as_u16(),
        res.status().to_string(),
    )));
}

let body = res.text().await?;
let html = Html::parse_document(&body);
let h2_selector = Selector::parse("h2").unwrap();
let mut table_element = h2_element.next_sibling_element().unwrap(); // error occured here

It can be solved with add this to Cargo.toml selectors = "0.22.0"

and add this to source code use selectors::Element;

But, only add 0.22.0 can sovle this problem, and the current version of selectors is already 0.24.0.

So, any other ideas to solve this problems?

adamreichold commented 1 year ago

This is fixed by #98 which re-exports Element thereby avoiding the extra dependency.

cfvescovo commented 1 year ago

This is fixed by #98 which re-exports Element thereby avoiding the extra dependency.

Looks like we need to publish a new release soon, #98 was merged 2 months ago