如何在Selenium(Python+Chrome)中通过代理加载HTTPS网站?
1. Confirm Proxy Supports HTTPS Traffic
Most HTTP proxies block the CONNECT method required to tunnel HTTPS traffic. Test your proxy directly with curl to verify:
curl -x http://118.69.134.2:80 https://httpbin.org/ip
If this command fails, your proxy doesn’t handle HTTPS—switch to a proxy that explicitly supports both HTTP and HTTPS protocols.
2. Explicitly Define Proxy Protocols
Some setups require separate proxy configurations for HTTP and HTTPS. Update your --proxy-server argument to include both:
from selenium import webdriver from selenium.webdriver.common.by import By proxy_config = "http://118.69.134.2:80;https://118.69.134.2:80" chrome_options = webdriver.ChromeOptions() chrome_options.add_argument(f'--proxy-server={proxy_config}') driver = webdriver.Chrome(options=chrome_options) driver.get("https://httpbin.org/ip") print(driver.find_element(By.TAG_NAME, "body").text) driver.quit()
3. Add Proxy Authentication (If Required)
If your proxy uses username/password authentication, include credentials directly in the proxy URL:
http_proxy = "http://your_username:your_password@118.69.134.2:80"
Note: Avoid hardcoding credentials in production code—use environment variables instead.
4. Rule Out SSL Certificate Issues (Test Only)
Temporarily disable Chrome’s SSL verification to check if certificate errors are causing the timeout (never use this in production):
chrome_options.add_argument('--ignore-certificate-errors') chrome_options.add_argument('--ignore-ssl-errors')
5. Test with a Functional Proxy
The proxy 118.69.134.2:80 may be offline or blocked. Try a known-working proxy to confirm the issue isn’t specific to this server.
内容的提问来源于stack exchange,提问作者کیا عباسی

