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)

测试结果

相关推荐
m0_6197311911 分钟前
TCP协议实战
网络·网络协议·tcp/ip
Arva .18 分钟前
TCP 的粘包 / 拆包机制
网络·网络协议·tcp/ip
每日出拳老爷子32 分钟前
[Python自动化] 用 Python + Selenium 做一个“浏览器重复操作录制器”:录一次,自动点一百次(附GUI+源码)
python·selenium·自动化
阿蔹32 分钟前
Selenium
软件测试·selenium·测试工具·自动化
✎ ﹏梦醒͜ღ҉繁华落℘1 小时前
计算机网络学习-- IP 报文和 ICMP 报文
学习·tcp/ip·计算机网络
车载测试工程师1 小时前
CAPL学习-SOME/IP交互层-客户端API函数
网络·学习·tcp/ip·capl·canoe
koping_wu1 小时前
【计算机网络】OSI七层模型、TCP协议、HTTP协议
tcp/ip·计算机网络·http
feathered-feathered1 小时前
网络套接字——Socket网络编程(TCP编程详解)
java·网络·后端·网络协议·tcp/ip
车载测试工程师18 小时前
CAPL学习-ETH功能函数-方法类4
网络协议·tcp/ip·以太网·capl·canoe
hnlq18 小时前
基于dpdk的用户态协议栈的实现(三)—— TCP的三次握手实现
网络·网络协议·tcp/ip