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)

测试结果

相关推荐
科技块儿9 小时前
IP定位技术:游戏反外挂体系中的精准识别引擎
数据库·tcp/ip·游戏
上海云盾安全满满11 小时前
选择高防IP时需要重点关注哪些因素
网络·网络协议·tcp/ip
a努力。11 小时前
字节Java面试被问:TCP的BBR拥塞控制算法原理
java·开发语言·python·tcp/ip·elasticsearch·面试·职场和发展
qq 137401861112 小时前
yyt0681.15标准解读:无菌医疗器械YY/T 0681.15运输包装的安全守护密码
功能测试·可用性测试·安全性测试
小快说网安13 小时前
AI 短剧平台的 “保命符”:高防 IP 如何抵御流量攻击与业务中断风险
人工智能·网络协议·tcp/ip
qq 137401861114 小时前
ASTM D4169低气压测试全解析:在稀薄空气中astmd4169守护运输安全
功能测试·可用性测试·安全性测试
0思必得015 小时前
[Web自动化] Selenium中Select元素操作方法
前端·python·selenium·自动化·html
Maỿbe17 小时前
TCP与UDP的探究
网络协议·tcp/ip·udp
月明长歌17 小时前
Selenium中隐式等待(Implicit Wait)和显式等待(Explicit Wait)的区别
前端·javascript·selenium
郝学胜-神的一滴18 小时前
深入浅出网络协议:从OSI七层到TCP/IP五层模型全解析
开发语言·网络·c++·网络协议·tcp/ip·程序人生