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)

测试结果

相关推荐
禹凕13 小时前
机器学习之Selenium(Machina Learning about Selenium)
爬虫·python·selenium·测试工具·机器学习
ITxiaobing202316 小时前
自研 IP 库与 AppsFlyer 判定不一致的排查实践
网络·网络协议·tcp/ip
2501_9378609416 小时前
中篇:TCP 为什么可靠又高效?滑动窗口、流量控制、拥塞控制与粘包全解析
服务器·网络·tcp/ip
SDWAN_Cheap18 小时前
TCP滑动窗口与拥塞控制是什么?从流量控制到网络稳定性的完整解析
网络·tcp/ip·php
YumiProxy18 小时前
动态IP冲突排查实战:从ARP检测到DHCP地址池的完整链路
服务器·网络·网络协议·tcp/ip·ip
CHENKONG_CK19 小时前
RFID 赋能汽车零部件涂装产线,构建全流程数字化追溯体系
网络·人工智能·单片机·网络协议·tcp/ip·汽车
平头哥~20 小时前
从文化 IP 解读到伴手礼定制,文创设计师智能体背后是 端到端具身交互智能落地
网络协议·tcp/ip·交互
P1Browser1 天前
换了 IP 还是被关联:WebRTC 泄露本地 IP 的三种触发路径
网络协议·tcp/ip·webrtc
ZhangJun951 天前
三次握手、四次挥手的具体细节和流程详解,附加思考题
tcp/ip·计算机网络·云计算
2501_937860942 天前
下篇:网络层、数据链路层与应用层:IP、NAT、ARP、DNS 一网打尽
网络·网络协议·tcp/ip