步骤 2:配置 Bright Data 代理设置你的 Bright Data 代理凭据并构建代理 URL:
# Bright Data Proxy Configurationproxy_host = "brd.superproxy.io"proxy_port = "port" # Replace with your port numberproxy_username = "username" # Replace with your Bright Data usernameproxy_password = "password" # Replace with your Bright Data password# Full Proxy URLproxy = f"http://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}"
# Navigate to a test site print("Connecting to target website...") driver.get("http://httpbin.org/ip") # Print the page content print("Page content:") print(driver.page_source) # Close the browser driver.quit()
步骤 6:验证输出运行脚本时,浏览器或控制台将显示代理 IP,如下示例:
{ "origin": "123.45.67.89"}
通过将 Bright Data 代理与 Selenium 集成,你可以更安全、更高效地自动化网页交互。无论是测试 Web 应用、抓取动态内容,还是访问区域限制网站,Bright Data 都能为你的自动化场景提供可靠性与隐私保护。立即开始使用 Bright Data 和 Selenium 构建更智能的自动化工作流吧!