The no_browser
crate strives to provide a high-level API for programmatically interacting with web pages through
a light-weight, head-less "web browser". This is not a real web browser, like Firefox or Chrome.
no_browser
builds on top of reqwest handling http requests, http redirects and
cookie management, as well as, scraper parsing html code. This crate uses
CSS selectors to freely access any element of a
given web page. It also provides its own abstraction to fill out and submit web forms.
However, no_browser
has no support for client-side JavaScript or any concept of actually rendering web pages. So if
you want to test modern JavaScript-driven web apps, opt for a crate driving a real web browser like
fantoccini or thirtyfour, instead.
```rust,no_run let browser = Browser::builder().finish()?;
// Lets go to the Wikipedia main page let page = browser.navigate_to("https://en.wikipedia.org/", None)?;
// the title tag should be "Wikipedia, the free encyclopedia" asserteq!( page.selectfirst("head > title")?.inner_html(), "Wikipedia, the free encyclopedia" );
// the main page should welcome us assert!(page .selectfirst("h1 > span.mw-headline")? .innerhtml() .starts_with("Welcome to"));
// fill out the search form ... let searchform = page.formbyid("searchform")?; searchform .input(InputType::Search, "search")? .borrowmut() .setvalue(Some("rust programming language".to_owned()));
// ... and submit let page = browser.submitform(searchform, "go")?;
// the new title tag should be "Rust (programming language) - Wikipedia" asserteq!( page.selectfirst("head > title")?.inner_html(), "Rust (programming language) - Wikipedia" );
// The main title on the html page should be quite similar asserteq!( page.selectfirst("span.mw-page-title-main")?.inner_html(), "Rust (programming language)" );
// The main title should have a subtitle showing we've been redirected assert!(page .selectfirst("div#contentSub span.mw-redirectedfrom")? .innerhtml() .starts_with("(Redirected from"));
// The table of contents should have more than 10 entries assert!(page .select("div#vector-toc ul#mw-panel-toc-list li.vector-toc-list-item")? .len() > 10); ```
Licensed under either of
SPDX-License-Identifier: MIT OR Apache-2.0
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.