测试代理ip是否工作正常,将正常的代理ip提取出来
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)
测试结果
文章来源:https://www.toymoban.com/news/detail-807932.html
文章来源地址https://www.toymoban.com/news/detail-807932.html
到了这里,关于selenium代理ip可用性测试的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!