Selenium配置2Captcha代理无法访问芬兰保险网站的问题求助
Selenium配置2Captcha代理无法访问芬兰保险网站的问题求助
我现在碰到个棘手的问题:想用付费的2Captcha代理搭配Selenium访问芬兰的保险网站,这个代理用requests.get()测试完全没问题,但一放到Selenium里就失效了。
我已经做了这些排查动作:
- 手动验证过代理,确实能正常工作
- 尝试在ChromeOptions中添加了
--proxy-server参数 - 没有弹出明确的错误提示,就是页面一直加载不出来
页面打开后显示的是这个错误(抱歉是克罗地亚语):
下面是我写的最小可复现代码,大家可以帮忙看看哪里出问题了:
import requests from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time # Proxy credentials USERNAME = "your_username" PASSWORD = "your_password" PROXY_DNS = "your_proxy_ip:port" def test_proxy(): """Test if the proxy is working.""" proxy_url = f"http://{USERNAME}:{PASSWORD}@{PROXY_DNS}" proxies = {"http": proxy_url, "https": proxy_url} try: response = requests.get("http://ip-api.com/json", proxies=proxies, timeout=10) print("Proxy Response:", response.json()) except requests.RequestException as e: print("Proxy failed:", e) def setup_driver(): """Setup Selenium WebDriver with proxy.""" chrome_options = webdriver.ChromeOptions() proxy = f"http://{USERNAME}:{PASSWORD}@{PROXY_DNS}" chrome_options.add_argument(f"--proxy-server={proxy}") driver = webdriver.Chrome(options=chrome_options) return driver def test_website(): """Test if Selenium can access the website.""" driver = setup_driver() driver.get("https://www.if.fi/henkiloasiakkaat/vakuutukset/autovakuutus") try: WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.TAG_NAME, "body")) ) time.sleep(10) print("Page loaded successfully.") except: print("Failed to load the page.") driver.quit() if __name__ == "__main__": test_proxy() # Check if proxy works via requests test_website() # Check if proxy works with Selenium
备注:内容来源于stack exchange,提问作者SolidOpt
相关产品推荐
相关产品推荐

