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)

测试结果

相关推荐
wsad053217 分钟前
CentOS 7 Minimal 配置静态 IP 完整指南(VMware NAT 模式)
linux·tcp/ip·centos
Trouvaille ~1 小时前
【Linux】TCP vs UDP深度对比:如何选择与用UDP实现可靠传输
linux·网络·c++·tcp/ip·udp·操作系统
0思必得01 小时前
[Web自动化] Selenium获取网页元素在桌面上的位置
前端·python·selenium·自动化
半壶清水11 小时前
[软考网规考点笔记]-OSI参考模型与TCP/IP体系结构
网络·笔记·tcp/ip
IP搭子来一个11 小时前
2026年动态IP代理怎么选:共享好还是独享好?
服务器·网络协议·tcp/ip
测试渣13 小时前
测试左移实战:如何在需求阶段拦截80%缺陷?
selenium·pytest·测试覆盖率
德育处主任Pro14 小时前
『NAS』设置内网固定 IP
网络·网络协议·tcp/ip
那就回到过去16 小时前
拥塞管理和拥塞避免
运维·服务器·网络·网络协议·tcp/ip·ensp
匀泪18 小时前
云原生(IP 透传,HAProxy 四层负载均衡实验)
tcp/ip·云原生·负载均衡
之歆18 小时前
Linux 网络配置与 TCP/IP 协议
linux·网络·tcp/ip