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)

测试结果

相关推荐
xiaoxiangsiyan6 小时前
HCIA 网络技术基础核心模块详解
运维·网络·网络协议·tcp/ip·运维开发·网络基础
liwulin050612 小时前
【PYTHON】使用Selenium + ChromeDriver以及XPATH语法
开发语言·python·selenium
Bobolink_12 小时前
IP更换频率:账号运营里多久换一次IP算正常
大数据·网络协议·tcp/ip
treesforest13 小时前
你的IP干净吗?
网络·网络协议·tcp/ip·跨境电商·ip归属地查询·跨境
llllll15213 小时前
深入浅出计算机网络:从 TCP 可靠传输到 DNS 解析核心原理
网络协议·tcp/ip·计算机网络
Patrick在香港13 小时前
Python爬虫框架实战:优雅抓取香港政府公开API数据的通用方案
java·开发语言·爬虫·python·ai编程·数据可视化·可用性测试
峥无14 小时前
《TCP/IP协议栈详解:协议分层·封装分用·地址管理》
网络·网络协议·tcp/ip
GDAL1 天前
Nginx TCP/UDP四层转发(Stream模块)完整深入教程
tcp/ip·nginx·udp
fhqlongteng2 天前
TCP服务器断开客户端的方法
服务器·网络·tcp/ip