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)

测试结果

相关推荐
ITxiaobing202330 分钟前
自研 IP 库与 AppsFlyer 地理位置判定不一致,该如何排查?
网络·数据库·tcp/ip
ZeroNews内网穿透1 小时前
内网穿透公网暴露防护:边缘网关 IP 黑白名单运维实践
运维·网络协议·tcp/ip·内网穿透·api安全·企业网络安全·运维实践
honsor1 小时前
机房动环监控:以太网温湿度传感器选型与部署全解
运维·服务器·网络·物联网·网络协议·tcp/ip
Novproxy_Z1 小时前
账号批量封禁复盘:从日志定位是 IP 关联还是行为指纹关联
网络·数据库·tcp/ip
honsor1 小时前
以太网温湿度传感器原理与 Modbus TCP 组网实战,机房动环监控落地
网络·嵌入式硬件·物联网·网络协议·tcp/ip
花间相见12 小时前
【计算基础|网络14】网络层:IP、ICMP 与 ping
网络·网络协议·tcp/ip
OnlineProxy12 小时前
为 LangChain 和 CrewAI 构建自定义工具:将代理 IP 轮换封装至智能体函数中
网络协议·tcp/ip·langchain
睿智の男孩15 小时前
MIG IP核对DDR3的输出时序分析记录
网络·网络协议·tcp/ip
一只小鱼儿吖17 小时前
代理 IP 实战指南:住宅/机房代理选型策略
网络·网络协议·tcp/ip
XiaoMaqqqq18 小时前
目前正规的IP驱动产业新场景新工具哪个好
网络·python·网络协议·tcp/ip