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)

测试结果

相关推荐
黄昏晓x1 天前
Linux ---- UDP和TCP
linux·tcp/ip·udp
favour_you___1 天前
epoll惊群问题与解决
服务器·网络·tcp/ip·epoll
小白学大数据1 天前
Selenium+Python 爬虫:动态加载头条问答爬取
爬虫·python·selenium
.select.1 天前
TCP 3
服务器·网络·tcp/ip
情绪雪1 天前
IP 协议基本原理
网络·网络协议·tcp/ip
小快说网安1 天前
高防 IP 的 “防护上限”:带宽、清洗能力、防御类型如何匹配业务需求
网络·tcp/ip·安全
不会写DN1 天前
如何设计应用层 ACK 来补充 TCP 的不足?
开发语言·网络·数据库·网络协议·tcp/ip·golang
不会写DN1 天前
如何给 Go 语言的 TCP 聊天服务加上 ACK 可靠送达机制
开发语言·tcp/ip·golang
fei_sun1 天前
数字积木(IP)设计流程
服务器·网络·tcp/ip
CDN3601 天前
高防服务器被攻击后 IP 被封?黑洞解封与清洗策略设置
运维·服务器·tcp/ip