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)

测试结果

相关推荐
80s7773 小时前
什么是动态IP?静态IP和动态IP有什么区别?
网络·网络协议·tcp/ip
星核0penstarry4 小时前
文本之外:API 如何接入图像生成能力
图像处理·ai作画·可用性测试·人工智能作画·风景
夜月yeyue9 小时前
SOME/IP-SD 服务发现故障
网络·单片机·网络协议·tcp/ip·安全·服务发现
你我一见如故9 小时前
仿QQ音乐桌面客户端——测试报告
python·selenium
λqaq710 小时前
MySQL 数据库基础(2)约束、用户权限、远程连接、外键与 TCP/UDP 理解
linux·数据库·python·tcp/ip·mysql
初願致夕霞11 小时前
《为什么公网访问不了内网?正向代理、内网穿透与 NAT 打洞一次说清》
linux·网络·tcp/ip·智能路由器
xxy2224111 小时前
Linux 网络编程入门(一):从 OSI 模型到 TCP Socket 编程
网络·tcp/ip·tcp
影寂ldy13 小时前
C# WinForm TCP-Socket
网络·tcp/ip·c#
影寂ldy15 小时前
C# WinForm TCP聊天室(服务端+客户端)
windows·tcp/ip·c#
Shawn Dev15 小时前
没有公网 IP,如何让家里的服务器通过域名访问?——Cloudflare Tunnel 实战指南
服务器·网络协议·tcp/ip