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)

测试结果

相关推荐
忘了ʷºᵇₐ9 天前
Linux系统能ping通ip但无法ping通域名的解决方法
linux·服务器·tcp/ip
2501_915921439 天前
后台发热、掉电严重?iOS 应用性能问题实战分析全过程
websocket·网络协议·tcp/ip·http·网络安全·https·udp
创小匠10 天前
创客匠人洞察:2025 创始人 IP 打造六大趋势与知识变现新路径
网络·网络协议·tcp/ip
sibo_yzm10 天前
EtherCAT转EtherNet/IP网关CEI-382
linux·网络·tcp/ip
西岭千秋雪_10 天前
计算机网络学习笔记:Wireshark观察TCP通信
笔记·学习·tcp/ip·计算机网络·wireshark
00后程序员张10 天前
用Fiddler抓包工具优化API联调流程:与Postman、Wireshark协作实践分享
websocket·网络协议·tcp/ip·http·网络安全·https·udp
笑口常开的小丸子10 天前
Selenium等待机制详解:从原理到实战应用
selenium
诗酒当趁年华11 天前
nacos热更新引起tcp激增导致服务不可用
java·tcp/ip·spring cloud
篱笆院的狗11 天前
到底什么是 TCP 连接?
网络·网络协议·tcp/ip
muyun280011 天前
《TCP/IP详解 卷1》读书心得及基于RFC手撮一个TFTP Server
java·网络·网络协议·tcp/ip