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)

测试结果

相关推荐
apihz4 小时前
随机驾考题目(C 照科一 / 科四 2000+ 题)免费API调用教程
android·java·c语言·开发语言·网络协议·tcp/ip
猫头虎9 小时前
城市级IP代理:赋能全球企业本地化数字增长与安全合规 | Decodo 德口多
网络·python·网络协议·tcp/ip·安全·pandas·pip
云栖梦泽在11 小时前
跨境电商账号频繁验证怎么办?从公网 IP、ASN、浏览器环境到登录稳定性排查
网络·网络协议·tcp/ip·网络安全·性能优化
WZF-Sang11 小时前
TCP和UDP协议
linux·服务器·网络·c++·学习·tcp/ip·udp
孫治AllenSun12 小时前
【Linux】服务器设置固定ip
linux·服务器·tcp/ip
云栖梦泽在12 小时前
在线 IP 检测工具能看到哪些信息?从公网 IP、ASN 到浏览器环境一文讲清
网络·网络协议·tcp/ip
IP搭子来一个1 天前
爬虫代理IP怎么选?短效代理 vs 隧道代理选型指南(2026最新)
爬虫·tcp/ip
KaMeidebaby1 天前
卡梅德生物技术快报|纳米抗体技术全套实操流程:AFB1 全合成文库淘选 + 分子对接定点突变参数手册
人工智能·python·tcp/ip·算法·机器学习
云栖梦泽在1 天前
原生 IP、机房 IP、住宅 IP、广播 IP 有何不同?从网络身份到 ASN 识别的技术科普
网络·网络协议·tcp/ip·性能优化
从零开始的代码生活_1 天前
Linux epoll 多路转接详解
linux·运维·网络·后端·tcp/ip·计算机网络·php