thulp-browser
Browser automation and web scraping utilities for Thulp.
Overview
This crate provides tools for web page fetching, HTML content extraction, and browser automation. It supports basic HTTP fetching out of the box and optional Chrome DevTools Protocol (CDP) integration for full browser automation.
Features
- Web Page Fetching: Simple async HTTP client for fetching web pages
- HTML Content Extraction: Extract text content and page titles from HTML
- CDP Support: Optional Chrome DevTools Protocol integration for advanced browser automation
- Page Metadata: Access page URL, status code, title, and content
- Async Design: Built on tokio and reqwest for efficient async operations
Installation
Add to your Cargo.toml:
[]
= "0.2"
For CDP browser automation support:
[]
= { = "0.2", = ["cdp"] }
Usage
Basic Web Fetching
use WebClient;
async
Working with Page Content
use ;
async
CDP Browser Automation (requires cdp feature)
use ;
async
Page Structure
The Page struct contains:
- url: The URL of the fetched page
- html: Raw HTML content
- title: Extracted page title (if found)
- status: HTTP status code
Error Types
The crate provides detailed error types for different failure scenarios:
BrowserError::Http: HTTP request failuresBrowserError::Parse: HTML parsing errorsBrowserError::InvalidUrl: Invalid URL formatBrowserError::CdpConnection: CDP connection failuresBrowserError::CdpProtocol: CDP protocol errorsBrowserError::BrowserLaunch: Browser launch failuresBrowserError::Navigation: Page navigation failuresBrowserError::JavaScriptEval: JavaScript evaluation failuresBrowserError::Screenshot: Screenshot capture failuresBrowserError::Timeout: Operation timeout
Feature Flags
| Flag | Description |
|---|---|
cdp |
Enable Chrome DevTools Protocol support |
Testing
# Run tests
# Run tests with CDP feature
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.