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)

测试结果

相关推荐
cui_ruicheng3 小时前
Linux网络编程(七):TCP Socket编程与EchoServer
linux·服务器·网络·tcp/ip
2601_957882246 小时前
多平台数字内容集群的版权合规与风控体系:从查重检测到IP保护的技术实践
人工智能·网络协议·tcp/ip
TechWayfarer6 小时前
营销反作弊实战:用IP归属地查询平台识别虚假流量
网络·python·网络协议·tcp/ip·数据分析
@encryption7 小时前
计算机网络 --- OSPF
网络·tcp/ip·计算机网络
源远流长jerry10 小时前
LVS 与 Nginx 负载均衡:从原理到生产实战
运维·网络·网络协议·tcp/ip·nginx·负载均衡·lvs
仍然.10 小时前
网络层IP协议
服务器·网络协议·tcp/ip
花阴偷移20 小时前
Ubuntu 22.04版本下配置静态IP
linux·运维·服务器·tcp/ip·ubuntu
xiaoshuaishuai81 天前
C# 签名异常与Gas预估失败调试方案
开发语言·网络·tcp/ip·c#
IP搭子来一个1 天前
舆情监控系统怎么接入代理 IP?多平台多账号采集的配置全流程
网络协议·tcp/ip·数据分析
小贾要学习1 天前
【Linux】基于自定义TCP协议的日期计算器
linux·网络·c++·网络协议·tcp/ip