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)

测试结果

相关推荐
CHENKONG_CK2 天前
破解制鞋打磨痛点:RFID赋能去毛刺工序自动化升级
网络·单片机·嵌入式硬件·网络协议·tcp/ip
把头塞进显示器2 天前
电商平台-测试报告
python·selenium·pytest
开开心心就好2 天前
安卓手写文字生成工具,多种纸张一直免费
网络·网络协议·tcp/ip·leetcode·智能手机·电脑·模拟退火算法
渡我白衣2 天前
HttpRequest与HttpResponse的实现
服务器·数据结构·c++·人工智能·tcp/ip·机器学习·caffe
IpdataCloud3 天前
如何判断游戏注册IP是住宅宽带还是机房代理?IP风险识别看ASN、IDC标签与风险分
tcp/ip·ip
酣大智4 天前
华为 VRRP的抢占延迟时间
网络·tcp/ip·vrrp
酣大智4 天前
网络协议计时器 & 发包间隔汇总
运维·网络·tcp/ip
IpdataCloud4 天前
AI智能体调用工具怎么核验来源IP?归属地、网络类型与代理风险识别(含Python代码)
数据库·python·tcp/ip
ITxiaobing20235 天前
IP 地理定位数据库的技术选型:数据源、格式与精度对比
tcp/ip
ITxiaobing20236 天前
企业级 IP 定位服务选型:从精度、字段到部署架构的工程化考量
tcp/ip