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)

测试结果

相关推荐
晚枫歌F9 小时前
TCP协议详解
网络·网络协议·tcp/ip
tang777899 小时前
Python爬虫代理,选短效IP还是长效IP?
爬虫·python·tcp/ip
_F_y11 小时前
网络层协议:IP
网络·tcp/ip·php
科技块儿11 小时前
我应该如何选择并使用IP数据库评估不同地区的定位精度(⊙_⊙?)
网络·网络协议·tcp/ip
阿蔹14 小时前
UI测试自动化-Web-Python-Selenium-2-元素操作、浏览器操作
前端·python·selenium·ui·自动化
Channon_17 小时前
双网卡绑定、软PRP、硬PRP技术解析:区别与联系
物联网·网络协议·可用性测试
袁煦丞 cpolar内网穿透实验室17 小时前
无需公网 IP 也能全球访问本地服务?cpolar+Spring Boot+Vue应用实践!
vue.js·spring boot·tcp/ip·远程工作·内网穿透·cpolar
Ancelin安心18 小时前
计算机网络易混淆知识点总结
网络协议·tcp/ip·计算机网络·nginx·网络安全·docker·云原生
RisunJan18 小时前
Linux命令-ifcfg命令(临时配置网络接口的IP地址)
linux·运维·tcp/ip