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)

测试结果

相关推荐
Ether IC Verifier19 分钟前
TCP三次握手与四次挥手详解
网络·网络协议·tcp/ip·计算机网络
pengyi8710158 小时前
独享IP池自动化维护方案,智能检测自动延长使用寿命
网络协议·tcp/ip·自动化
影sir15 小时前
Selenium常用函数(窗口与弹窗)
selenium·测试工具
XiYang-DING15 小时前
【Java EE】TCP—可靠传输
网络·tcp/ip·java-ee
dangdanding16 小时前
防火墙 IP 分片测试套件-fragroute
linux·网络·网络协议·tcp/ip
TechWayfarer16 小时前
AI大模型时代:IP数据云如何适配智能体场景需求
开发语言·人工智能·python·网络协议·tcp/ip·langchain
XiYang-DING17 小时前
【Java EE】TCP—延时应答
网络·tcp/ip·java-ee
XiYang-DING17 小时前
【Java EE】TCP—流量控制和拥塞控制
java·tcp/ip·java-ee
Ether IC Verifier18 小时前
TCP/IP协议握手原理详解——结合以太网连接过程
服务器·网络·数据库·网络协议·tcp/ip
山栀shanzhi19 小时前
TCP 和 UDP 区别
网络协议·tcp/ip·udp