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)

测试结果

相关推荐
Hello_Embed16 分钟前
嵌入式上位机开发入门(二十八):JSON 与 JsonRPC 入门
网络·笔记·网络协议·tcp/ip·嵌入式
东北甜妹36 分钟前
TCP/IP和VLAN
网络协议·tcp/ip·面试
阿正的梦工坊3 小时前
计算机网络 IP 地址分配
网络·tcp/ip·计算机网络
聊点儿技术3 小时前
物联网设备IP归属地查询实操指南
物联网·tcp/ip·ip·ip归属地查询·ip地址查询·查ip归属地
UrSpecial3 小时前
TCP服务器并发模型:单线程、多线程与Select实现
服务器·网络·网络协议·tcp/ip
pengyi8710153 小时前
IP被封禁应急处理,动态IP池快速更换入门
大数据·网络·网络协议·tcp/ip·智能路由器
被摘下的星星14 小时前
网际协议(IP协议)
网络·tcp/ip
Elastic 中国社区官方博客16 小时前
Elastic Security、Observability 和 Search 现在在你的 AI 工具中提供交互式 UI
大数据·运维·人工智能·elasticsearch·搜索引擎·安全威胁分析·可用性测试
发光小北18 小时前
IEC104 转 Modbus TCP 网关如何应用?
网络·网络协议·tcp/ip
小宏运维有点菜19 小时前
服务器 BMC 管理 IP
服务器·tcp/ip·centos