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)

测试结果

相关推荐
Cx330❀4 小时前
【Linux网络】网络层协议 IP :从网络层原理到 Linux 内核源码
linux·运维·服务器·网络·tcp/ip·ai·ai编程
ITxiaobing20235 小时前
广告归因场景下的IP情报工程化:提升AppsFlyer P360匹配精度的实践思路
大数据·人工智能·tcp/ip
2601_962298278 小时前
Python与Selenium结合的Web自动化测试全流程实践教程
自动化测试·python·selenium·web测试·pageobjectmodel
CC城子9 小时前
EtherNet/IP I/O 丢包排查(linux系统)
linux·单片机·tcp/ip·ethernetip
M78佐菲10 小时前
HTML学习笔记
linux·笔记·学习·tcp/ip·html
酒神dnspup12 小时前
DNSPup 免费体验监控指南:证书、DNS、IP、端口和网页一站式监控
网络协议·tcp/ip·iphone·网站监控
Cx330❀12 小时前
【Linux网络】深入TCP协议:从滑动窗口到拥塞控制与性能优化全景解析
linux·开发语言·网络·tcp/ip·ai·性能优化·ai编程
2601_9622982715 小时前
【自动化测试】基于Selenium + Python的web自动化框架
自动化测试·python·selenium·测试用例·web框架
小此方17 小时前
Linux网络(七):从 Socket 封装到应用层协议:手写网络版计算器,彻底搞懂 TCP 通信、序列化与反序列化
linux·网络·tcp/ip
春风解人意1 天前
从零开始学习嵌入式P32----网络基础之TCP
c语言·网络·学习·tcp/ip