Skip to main content

test_google_html_fetch/
test_google_html_fetch.rs

1use anyhow::Result;
2use headless_engine::network::client::NetworkClient;
3use headless_engine::network::fingerprint::DeviceProfile;
4
5#[tokio::main]
6async fn main() -> Result<()> {
7    let client = NetworkClient::with_profile(DeviceProfile::ChromeWindows)?;
8
9    let urls = [
10        "https://www.google.com/search?q=Rust+programming+language&udm=14&hl=en",
11        "https://www.google.com/search?q=Rust+programming+language&gbv=1&hl=en",
12        "https://www.google.com/search?q=Rust+programming+language&hl=en",
13    ];
14
15    for url in urls {
16        println!("--------------------------------------------------");
17        println!("Fetching: {}", url);
18        let res = client.fetch(url).await?;
19        println!("Status: {}", res.status);
20        println!("Bytes:  {}", res.html.len());
21        println!("Contains search results container: {}", res.html.contains("id=\"search\"") || res.html.contains("class=\"g\"") || res.html.contains("<h3") || res.html.contains("id=\"rso\""));
22        println!("Contains fallback/sorry:           {}", res.html.contains("having trouble accessing") || res.html.contains("sorry/index"));
23    }
24
25    Ok(())
26}