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)

测试结果

相关推荐
uyeonashi1 小时前
自动化测试问卷考试系统测试报告
功能测试·selenium·github
古译汉书1 小时前
【IoT死磕系列】Day 6:工业控制底层大动脉—CAN总线
linux·网络·arm开发·单片机·物联网·tcp/ip
007张三丰1 小时前
软件测试专栏(6/20):Selenium从0到1实战指南:元素定位、等待机制与框架封装
selenium·测试工具
科技块儿3 小时前
【数据亲测】商业IP库在广告ab测试中的roi提升效果分析
网络·tcp/ip·ab测试
czxyvX6 小时前
019-Linux-Socket编程-TCP
linux·tcp/ip
网络安全-老纪15 小时前
一文2000字手把手教你自动化测试Selenium+pytest+数据驱动
自动化测试·软件测试·selenium·测试工具·pytest
宁雨桥18 小时前
详解Web服务部署:IP+端口 vs IP+端口+目录 实战指南
前端·网络协议·tcp/ip
小灰灰搞电子20 小时前
ESP32 使用ESP-IDF实现Modbus TCP主机通信源码分享
网络·modbustcp·网络协议·tcp/ip·esp32
wanderist.1 天前
从 TCP 到 JSON:一次 FastAPI + LLM 生产环境 “Unexpected end of JSON input” 的底层剖析
tcp/ip·json·fastapi
cheems95271 天前
【网络原理】网络编程基础:TCP Echo Server 的底层逻辑与实现
网络·tcp/ip·php