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)

测试结果

相关推荐
卖个几把萌2 小时前
【16】Selenium+Python 接管已打开谷歌浏览器
python·selenium·测试工具
熙xi.3 小时前
以太网帧格式、IP数据报头部、TCP头部、UDP头部
网络·tcp/ip·udp
light_forest5 小时前
tcp_connect_v4接口
java·网络·tcp/ip
Matana1117 小时前
Vmware中主机ip a没有ip地址
服务器·网络·tcp/ip
2501_938810118 小时前
共享IP的定义
服务器·网络·tcp/ip
爱吃汽的小橘9 小时前
MIPI DSI和MIPI Tx IP 的建立
网络·网络协议·tcp/ip
newxtc9 小时前
【辽宁政务服务网-注册_登录安全分析报告】
运维·selenium·安全·政务·安全爆破
蜗牛^^O^9 小时前
OSI七层模型与TCP/IP 四层模型
网络·网络协议·tcp/ip
z10_1412 小时前
海外住宅ip怎么区分干净程度以及怎么选择海外住宅ip
服务器·网络·网络协议·tcp/ip
进击的圆儿12 小时前
10个Tcp三次握手四次挥手题目整理
网络·tcp/ip