selenium代理ip可用性测试

测试代理ip是否工作正常,将正常的代理ip提取出来

python 复制代码
from selenium import webdriver
from fake_useragent import UserAgent
def check_proxy(proxy):
    print("开始测试:"+proxy)
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable‐gpu')
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")
    chrome_options.add_argument('--proxy-server=http://' + proxy)
    chrome_options.add_argument(f"user-agent={UserAgent().random}")
    
    try:
        driver = webdriver.Chrome(options=chrome_options)
        driver.get("https://www.baidu.com")
        # You can add additional checks or actions here if needed
        driver.quit()        
        # Write usable proxies to ip1.txt
        with open('ip1.txt', 'a') as f:
            f.write(proxy+"\n")
        print(f"代理 {proxy} 工作正常")
    except Exception as e:
        print(f"代理 {proxy} 无法工作")

with open('ip.txt', 'r') as f:
    for line in f:
        ip = line.strip()
        check_proxy(ip)

测试结果

相关推荐
ClouGence11 小时前
自动化测试,如何让每个用例都保持登录状态?
selenium·测试
ClouGence11 小时前
手动测试工程师有必要学自动化测试吗?手工测试还有前途吗?
selenium·测试·求职
treesforest11 小时前
你以为只是一串数字?你的IP地址,正在悄悄暴露这些信息
网络·网络协议·tcp/ip·网络安全·ip归属地查询·ip风控
拾光Ծ13 小时前
【Linux网络】网络通信实战:UDP & TCP Socket编程实现Echo Server
linux·网络·网络协议·tcp/ip·udp·线程池
派葛穆13 小时前
s7-200smart-tcp/ip通讯
网络协议·tcp/ip
小小测试开发1 天前
Playwright vs Selenium vs Cypress:从浏览器协议到 API 设计的全面对比与实测
人工智能·selenium·测试工具
玩转4G物联网1 天前
FS800DTU 新品上线|免费使用 DMP 设备管理平台,支持远程批量配置 & OTA 升级
物联网·网络协议·tcp/ip·云平台·核心板·fs800dtu·iot管理平台
wuqingshun3141591 天前
说说TCP的3次握手?为什么需要三次握手?
服务器·网络协议·tcp/ip
SLD_Allen1 天前
AI Agent可观测性:破解多步推理的“黑盒”困局
人工智能·可用性测试·观测
无锡耐特森1 天前
解决网关数据异常EtherNetIP 转Modbus TCP专用动态监测
网络·网络协议·tcp/ip