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)

测试结果

相关推荐
生而为虫11 小时前
Selenium打开网页时保持登陆状态
selenium·测试工具
天荒地老笑话么14 小时前
静态 IP 规划:掩码/网关/DNS 的正确组合
网络·网络协议·tcp/ip·网络安全
..过云雨16 小时前
多路转接select系统调用详解
网络·网络协议·tcp/ip
强风79417 小时前
Linux-传输层协议TCP
linux·网络·tcp/ip
科技块儿18 小时前
如何选择合适的IP查询工具?精准度与更新频率全面分析
网络·tcp/ip·安全
Zach_yuan18 小时前
传输层之TCP/UDP 核心原理全解析:从协议基础到实战机制
linux·网络协议·tcp/ip·udp
云姜.18 小时前
TCP协议特性
服务器·网络·tcp/ip
我的xiaodoujiao18 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 47--设置Selenium以无头模式运行代码
python·学习·selenium·测试工具·pytest
不会代码的小测试1 天前
UI自动化-POM封装
开发语言·python·selenium·自动化