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)

测试结果

相关推荐
辣椒思密达3 小时前
AI出海产品本地化测试:住宅IP在模拟海外用户环境中的实践价值
网络协议·tcp/ip·安全·php·苹果vision pro
花生了什么事o6 小时前
DNS:把域名翻译成 IP 的层级查询机制
网络·网络协议·tcp/ip
其实防守也摸鱼7 小时前
渗透--损坏的对象级别鉴权漏洞(Broken Object Level Authorization, BOLA)
大数据·网络·数据库·学习·tcp/ip·安全·安全威胁分析
农村小镇哥7 小时前
如何限定IP访问Oracle数据库
数据库·tcp/ip·oracle
2401_873479408 小时前
金融合规新规下IP查询怎么做?用IP离线库实现数据不出域
网络协议·tcp/ip·金融·ip
大草原的小灰灰10 小时前
计算机网络与TCP/IP参考模型
tcp/ip·计算机网络
ClouGence12 小时前
8 款好用的 Web 自动化测试工具大盘点:怎么选、适合谁?
selenium·测试
Lhappy嘻嘻13 小时前
网络初识|基础入门:局域网广域网、IP 端口、TCP/IP 五层模型与封装解封装全过程
java·开发语言·网络·笔记·网络协议·tcp/ip
IpdataCloud1 天前
担心IP暴露隐私?用安全IP查询工具自查,三步配置网络出口
网络·tcp/ip·安全·ip
hehelm1 天前
Linux网络编程—TCP字典翻译系统
linux·开发语言·网络·c++·tcp/ip