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)

测试结果

相关推荐
xie_pin_an1 小时前
网络原理与编程实战:从 TCP/IP 到 HTTP/HTTPS
网络·tcp/ip·http
中草药z5 小时前
【自动化测试】Selenium详解-WebUI自动化测试
前端·功能测试·selenium·自动化·html·web·测试
九州ip动态20 小时前
如何安全使用改IP软件更改异地IP地址?
网络·tcp/ip·安全
dog2501 天前
难以超越的 TCP AIMD
网络协议·tcp/ip·php
qzhqbb1 天前
IP数据报相关内容
网络·网络协议·tcp/ip
小浣浣1 天前
为何她总在关键时“失联”?—— 解密 TCP 连接异常中断
网络·网络协议·tcp/ip
曳渔1 天前
UDP/TCP套接字编程简单实战指南
java·开发语言·网络·网络协议·tcp/ip·udp
.Shu.1 天前
计算机网络 TCP、UDP 区别
tcp/ip·计算机网络·udp
你好,赵志伟1 天前
Socket 编程 TCP
linux·服务器·tcp/ip
M1A12 天前
TCP协议详解:为什么它是互联网的基石?
后端·网络协议·tcp/ip