pub struct Page { /* private fields */ }
Expand description
Struct Page
represents a loaded and parsed web response.
It gives access to:
- response meta data, like http method (
method()
) used to access the page url (url()
), the http response status (status()
) and response headers (headers()
); - the unprocessed reponse body (
text()
); - individual query parameters form the page’s url (
query()
); - parsed html elements via CSS selectors either
by returning all matches (
select()
) or returning the first match only (select_first()
); - parsed html forms identified either by index (
form()
) or by id (form_by_id()
);
See the main docs of crate no_browser
for usage examples.
Implementations§
Source§impl Page
impl Page
Sourcepub const fn status(&self) -> &StatusCode
pub const fn status(&self) -> &StatusCode
Returns the http status code returned with this page.
Sourcepub const fn headers(&self) -> &HeaderMap
pub const fn headers(&self) -> &HeaderMap
Returns the response headers returned with this page.
Sourcepub const fn url(&self) -> &Url
pub const fn url(&self) -> &Url
Returns the url for this page. Due to server-side redirects this url may be different from the initial request.
Sourcepub fn form(&self, idx: usize) -> Result<&Form>
pub fn form(&self, idx: usize) -> Result<&Form>
Returns a reference to the form at index idx
from the list of forms on this page.
Sourcepub fn form_mut(&mut self, idx: usize) -> Result<&mut Form>
pub fn form_mut(&mut self, idx: usize) -> Result<&mut Form>
Returns a mutable reference to the form at index idx
from the list of forms on this page.
Sourcepub fn form_by_id(&self, id: &str) -> Result<&Form>
pub fn form_by_id(&self, id: &str) -> Result<&Form>
Returns a reference to the form with the given id
from the list of forms on this page.
Sourcepub fn form_by_id_mut(&mut self, id: &str) -> Result<&mut Form>
pub fn form_by_id_mut(&mut self, id: &str) -> Result<&mut Form>
Returns a mutable reference to the form with the given id
from the list of forms on this page.
Sourcepub fn select_first(&self, selectors: &str) -> Result<ElementRef<'_>>
pub fn select_first(&self, selectors: &str) -> Result<ElementRef<'_>>
Returns the first element matching the given CSS selector group, i.e. a comma-separated list of selectors. See W3Schools: CSS Selector Reference.
let title_element = page.select_first("head > title")?;
let title = title_element.inner_html();
Sourcepub fn select(&self, selectors: &str) -> Result<Vec<ElementRef<'_>>>
pub fn select(&self, selectors: &str) -> Result<Vec<ElementRef<'_>>>
Returns all elements matching the given CSS selector group, i.e. a comma-separated list of selectors. See W3Schools: CSS Selector Reference.
let elements = page.select("head > title")?;
let last_content = elements.first().unwrap().inner_html();