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)

测试结果

相关推荐
newxtc1 天前
【 广州产权交易所-注册安全分析报告-无验证方式导致安全隐患】
开发语言·人工智能·selenium·安全·yolo
虎头金猫1 天前
我的远程开发革命:从环境配置噩梦到一键共享的蜕变
网络·python·网络协议·tcp/ip·beautifulsoup·负载均衡·pandas
渡我白衣1 天前
网络层IP协议详解:互联网的灵魂所在
网络协议·tcp/ip·信号处理
马拉萨的春天1 天前
RTC、UDP、TCP和HTTP以及直播等区别
tcp/ip·udp·实时音视频
Turnsole_y1 天前
pycharm自动化测试初始化
python·selenium
asdfg12589631 天前
如何判断一个地址是否可以用作主机 IP 地址?
服务器·网络·tcp/ip
ytttr8732 天前
C语言实现Modbus TCP/IP协议客户端-服务器
服务器·c语言·tcp/ip
迷枫7122 天前
19.1 TCP 和 UDP 有什么区别?
网络·tcp/ip·udp
悟能不能悟2 天前
电脑没法ping通某个网段的ip
网络协议·tcp/ip·电脑
迎風吹頭髮2 天前
Linux服务器编程实践20-TCP服务 vs UDP服务:核心差异对比
linux·服务器·tcp/ip