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)

测试结果

相关推荐
Defry1 小时前
Selenium WebDriver和Chrome对照表
chrome·selenium·测试工具
爱码少年1 小时前
springboot工程中使用tcp协议
spring boot·后端·tcp/ip
小堃学编程8 小时前
计算机网络(十) —— IP协议详解,理解运营商和全球网络
网络·tcp/ip·计算机网络
小鹿( ﹡ˆoˆ﹡ )11 小时前
探索IP协议的神秘面纱:Python中的网络通信
python·tcp/ip·php
59678515415 小时前
DotNetty ChannelRead接收数据为null
tcp/ip·c#
hgdlip16 小时前
如何快速切换电脑的ip地址
网络·tcp/ip·电脑
程序员-珍17 小时前
虚拟机ip突然看不了了
linux·网络·网络协议·tcp/ip·centos
Death20018 小时前
使用Qt进行TCP和UDP网络编程
网络·c++·qt·tcp/ip
虽千万人 吾往矣18 小时前
golang gorm
开发语言·数据库·后端·tcp/ip·golang
前端张三1 天前
Mac 电脑pink 后端ip地址进行本地联调
服务器·tcp/ip·macos