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

Extract text from Html #141

Closed
MihirModi1421 opened this issue Oct 13, 2023 · 1 comment
Closed

Extract text from Html #141

MihirModi1421 opened this issue Oct 13, 2023 · 1 comment

Comments

@MihirModi1421
Copy link

MihirModi1421 commented Oct 13, 2023

Hi there @j-mendez initially thanks a lot for this spider awesome crate

i am using you example scrape.rs to scrape website and along with sublinks of that domain present in it
but it gives me raw html

i want to extract text from raw html provided via scrape any idea or advice is accepted

@j-mendez
Copy link
Member

j-mendez commented Oct 13, 2023

Hi @MihirModi1421 take a look at this example here to extract content as text https://github.com/seoderapp/seoder/blob/main/seoder_lib/src/packages/spider/fs.rs#L171C6-L171C6.

The main gist is to use Html::parse_document(&my_html) and element.text().map(|s| s.chars()).flatten().collect() for the element nodes to get the text content. You can use the selector crate to use CSS selectors to get exactly what you want or just iterate over all the nodes of Html::parse_document.

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