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)

测试结果

相关推荐
计算机安禾19 小时前
【计算机网络】第14篇:TCP连接管理的有限状态机模型——三次握手与四次挥手的严格推导
网络·tcp/ip·计算机网络
计算机安禾1 天前
【计算机网络】第16篇:TCP流量控制——接收窗口调度的缓冲管理问题
网络·tcp/ip·计算机网络
里晓山1 天前
SOME/IP协议(上)
网络·网络协议·tcp/ip·车载系统
wangl_921 天前
Modbus TCP/IP 地址完全解析手册
网络·tcp/ip·php·modbus·kepware·kepserverex
05候补工程师1 天前
[408考研笔记] 传输层与网络层核心辨析:从逻辑通信到滑动窗口计算
网络·经验分享·笔记·网络协议·tcp/ip·考研·ip
代码不停1 天前
软件测试分类
功能测试·可用性测试
代码中介商1 天前
Linux TCP 协议深度解析:从状态机到拥塞控制
linux·网络·tcp/ip
落羽的落羽1 天前
【网络】TCP与UDP协议使用指南,Socket编程实现Echo服务
linux·服务器·网络·c++·网络协议·tcp/ip·机器学习
怕什么真理无穷2 天前
C++面试5_ TCP 粘包2(工业级)
开发语言·c++·tcp/ip
雪度娃娃2 天前
基于TCP的网络词典
网络·c++·tcp/ip·c#