ip_list1 = [代理ip。。。]
def agency():
f= open('daili.txt','r')
for a in f:
a = a.strip('\n')
ip_list1.append(a)
print(a)
print(ip_list1)
for i in ip_list1:
item = i
print(item)
proxyHost = item
proxyPort = "3128"
proxyMeta = 'http://'+proxyHost+':'+proxyPort
print(proxyMeta)
proxies = {
"http": proxyMeta,
"https": proxyMeta,
}
print(proxies)
# 如果连接成功,且返回来内容认为ip可用,返回该ip退出循环
try:
rsp = requests.get("http://www.baidu.com", proxies=proxies)
print(rsp.text)
print('可用')
except :
print('不可用')
ip_list1.remove(item)
# time.sleep(3)