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)

测试结果

相关推荐
Qinana2 天前
从数据包旅程到首屏渲染:深入理解 TCP/IP 如何决定你的 Web 性能
前端·tcp/ip·浏览器
blasit8 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
gihigo199813 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
龙仔72513 天前
在麒麟V10服务器安全加固,sshd防暴力破解加固,实现“密码错误3次封IP”的需求
服务器·tcp/ip·安全
凯酱13 天前
Windows防火墙入站规则IP白名单
windows·网络协议·tcp/ip
上海云盾王帅13 天前
从底层守护:深度解析四层协议(TCP/UDP)的DDoS防护之道
tcp/ip·udp·ddos
IP搭子来一个13 天前
独享IP和共享IP怎么选?全面对比解析
运维·网络·tcp/ip
科技块儿13 天前
如何用离线库秒筛“数据中心”IP段并自动封号?
网络·网络协议·tcp/ip
xixi092413 天前
selenium IDE——command
selenium·测试工具
上海云盾第一敬业销售13 天前
选择最佳高防CDN与高防IP服务以保证网站安全
网络协议·tcp/ip·安全