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)

测试结果

相关推荐
WrkZmkvJ31 分钟前
博世汽车电驱仿真Simulink 模型, 同步电机和异步电机模型, 相电流完美波形 MPTA+...
tcp/ip
航哥的女人2 小时前
最小可运行示例(C++ TCP回显)
开发语言·c++·tcp/ip
天上飞的粉红小猪15 小时前
传输层UDP&&TCP
网络·tcp/ip·udp
7ACE19 小时前
Wireshark TS | TCP 零窗口探测时间
网络协议·tcp/ip·wireshark
Lightning-py21 小时前
TCP协议知识点
tcp/ip
jimy11 天前
从Windows terminal里面的输出内容中截取trim IP 地址,再更新到.ssh/config文件里面
windows·tcp/ip·ssh
leo_2321 天前
IP--SMP(软件制作平台)语言基础知识之六十四
服务器·开发语言·tcp/ip·企业信息化·smp(软件制作平台)·应用系统·eom(企业经营模型)
说私域1 天前
技术赋能直播运营:开源AI智能名片商城小程序助力个人IP构建与高效运营
人工智能·tcp/ip·小程序·流量运营·私域运营
czhc11400756631 天前
通信217
服务器·网络·tcp/ip