Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Find by Text #160

Closed
seongs1024 opened this issue Nov 9, 2023 · 1 comment
Closed

[Feature Request] Find by Text #160

seongs1024 opened this issue Nov 9, 2023 · 1 comment

Comments

@seongs1024
Copy link

In the case, select tags which are siblings of a tag containing some text.

I don't have clue to do that...
It would be great to have a method, find by name, like BeautifulSoup.

Thank you

@seongs1024
Copy link
Author

seongs1024 commented Nov 10, 2023

To get text of the sibling, this code works but look bad to me

fn find(html: &str, selector: Arc<Selector>, text: &str) -> String {
    let document = Html::parse_fragment(&html);
    document
        .select(&selector)
        .filter(|e| {
            let trimed = e.text().next().map(|e| e.trim());
            trimed == Some(text)
        })
        .flat_map(|e| e.next_sibling_element())
        .map(|e| e.text().collect::<String>())
        .map(|s| s.trim().to_string())
        .collect()
}

@cfvescovo cfvescovo closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants