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)

测试结果

相关推荐
magic_now2 小时前
Modbus RTU 与 TCP 学习笔记
笔记·学习·tcp/ip
饿了吃洗衣凝珠5 小时前
ospf笔记
网络·tcp/ip·智能路由器
江华森6 小时前
TCP/IP 网络协议学习笔记(含上机实操)
网络协议·学习·tcp/ip
ICT系统集成阿祥8 小时前
防火墙威胁告警溯源源 IP 完整方法(华为 USG / 华三 SecPath 通用)
网络·tcp/ip·华为
KaMeidebaby8 小时前
卡梅德生物技术快报|组蛋白乙酰化修饰调控动脉粥样硬化的分子机制及中药表观干预研究
网络·人工智能·网络协议·tcp/ip·算法
夜月yeyue8 小时前
TCP/IP 协议解析
linux·服务器·c语言·网络·网络协议·tcp/ip
Seven979 小时前
别只会说 HTTPS 更安全:一文吃透加密、证书与 TLS 握手
tcp/ip·http
xlq223229 小时前
63.tcp可靠性
网络·网络协议·tcp/ip
TechWayfarer9 小时前
IP精准定位服务接入实战:广告投放如何用位置数据做定向策略
python·网络协议·tcp/ip·flask
艾莉丝努力练剑9 小时前
【Linux网络】网络层IP协议(一)
linux·运维·服务器·网络·tcp/ip·计算机网络·udp