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)

测试结果

相关推荐
Chenyu_3105 小时前
AUTOSAR 与 SOME/IP 入门:车载通信是怎么从 CAN 走到 SOA 的
网络·网络协议·tcp/ip·汽车·autopilot
跨境猫小妹6 小时前
亚马逊后台登录频繁触发验证码:先查会话Cookie还是IP环境
服务器·tcp/ip·php·跨境电商·营销策略
大今野1 天前
第 17 章 IP 编址与子网划分
网络·网络协议·tcp/ip·专转本
晚枫歌F2 天前
DPDK实现tcp、udp协议栈生成so以及LD_PRELOAD适配redis和iperf3
redis·tcp/ip·udp
王亚博_Abel3 天前
域名是怎么变成 IP 的?手拆 DNS 解析四个实验实测
网络·网络协议·tcp/ip
神一样的老师3 天前
用 FCU1501 双网口打通两个不同网段:IP 转发 + NAT 实战
网络·网络协议·tcp/ip
fly-3354 天前
快速重传与快速恢复:TCP丢包的高效应对
服务器·网络·tcp/ip
FakeOccupational5 天前
fpga系列 HDL : 选择RAM IP(Two Port IP核) 乒乓缓冲(Ping-Pong Buffer)工作流程
网络协议·tcp/ip·fpga开发
云上工程笔记7 天前
企业大模型调用数据安全与合规怎么保障:2026 年等保、数据留存、密钥与 IP 白名单清单
数据库·网络协议·tcp/ip