最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rust - How to set a proxy with authentication when using the headless_chrome crate? - Stack Overflow

programmeradmin0浏览0评论
let proxy = format!("https://{}:{}@{}:{}", "username", "password", "proxy_host", "proxy_port");
let browser = Browser::new(LaunchOptions {
    headless: true,
    proxy_server: Some(&proxy),
    ..Default::default()
}).expect("Failed to launch browser");

This is my code to launch a headless browser using the headless_chrome crate. When I connect to site like the below, I get the error: Navigate failed: net::ERR_NO_SUPPORTED_PROXIES.

let tab = browser.new_tab().unwrap();

// Navigate to wikipedia
tab.navigate_to("/?src=header&redirect_to=%2F").expect("Error");

How can I fix this problem?

let proxy = format!("https://{}:{}@{}:{}", "username", "password", "proxy_host", "proxy_port");
let browser = Browser::new(LaunchOptions {
    headless: true,
    proxy_server: Some(&proxy),
    ..Default::default()
}).expect("Failed to launch browser");

This is my code to launch a headless browser using the headless_chrome crate. When I connect to site like the below, I get the error: Navigate failed: net::ERR_NO_SUPPORTED_PROXIES.

let tab = browser.new_tab().unwrap();

// Navigate to wikipedia
tab.navigate_to("https://www.semrush.com/login/?src=header&redirect_to=%2F").expect("Error");

How can I fix this problem?

Share Improve this question edited Feb 7 at 17:00 John Kugelman 362k69 gold badges548 silver badges595 bronze badges asked Feb 6 at 1:44 YukiYuki 237 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
let proxy = format!("http://{}:{}", "proxy_host", "proxy_port");
let launch_options = LaunchOptions::default_builder()
    .proxy_server(Some(&proxy))
    .build()
    .unwrap();
let browser = Browser::new(launch_options).expect("Failed to launch browser");

let tab = browser.new_tab().unwrap();
tab.wait_until_navigated().unwrap();

tab.enable_fetch(None, Some(true)).unwrap()
    .authenticate(Some("username".to_string()), Some("password".to_string())).unwrap()
    .navigate_to("https://example.com").unwrap()
    .wait_until_navigated().unwrap();

This is my solution. When using headless_chrome crate, we can't set the proxy with authentication directly like http://username:password@host:port format. Instead, we have authenticate function that enables to set the username and password on tab.

This link will be help. https://github.com/rust-headless-chrome/rust-headless-chrome/issues/417

发布评论

评论列表(0)

  1. 暂无评论