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)

测试结果

相关推荐
老蒋新思维11 小时前
陈修超入局:解锁 AI 与 IP 融合的创新增长密码
网络·人工智能·网络协议·tcp/ip·企业管理·知识付费·创客匠人
xxtzaaa11 小时前
告别IP关联烦恼,多部手机如何实现不同IP防封号
网络·网络协议·tcp/ip
汪汪队立大功12312 小时前
selenium中执行javascript,是否等价于在浏览器console位置执行
javascript·selenium·测试工具
tang7778912 小时前
代理IP的匿名性测试:如何验证你的真实IP是否已泄露?
网络·网络协议·tcp/ip
DKunYu12 小时前
5.网络原理之TCP_IP
网络·tcp/ip·php
不爱学英文的码字机器14 小时前
Rust 并发实战:使用 Tokio 构建高性能异步 TCP 聊天室
开发语言·tcp/ip·rust
AIwenIPgeolocation14 小时前
IP定位精度疑问:有些IP为什么难以达到街道级准确度?
服务器·网络·tcp/ip
liu****14 小时前
20.传输层协议TCP
服务器·网络·数据结构·c++·网络协议·tcp/ip·udp
百***359415 小时前
如何在树莓派部署Nginx并实现无公网ip远程访问内网制作的web网站
前端·tcp/ip·nginx
q***318917 小时前
如何查询SQL Server数据库服务器的IP地址
服务器·数据库·tcp/ip