接上一篇保存的IP地址,进行验证

# -*- coding: utf-8 -*-
import requests
from threading import Thread
import threading get_ip = open('get_ip.txt','r') headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:55.0) Gecko/20100101 Firefox/55.0'}
lock = threading.Lock() #使用线程锁 #利用多线程,在新浪IP接口上,验证IP
def verify_ip(): url = 'http://www.baidu.com' # 新浪IP接口
try:
# 先要获取锁:
lock.acquire()
ip = get_ip.readline().strip()
#解开锁
lock.release() proxies = {'http': ip} r = requests.get(url, headers=headers, proxies=proxies,timeout=5)
#如果requests成功,表示验证成功,打印出IP
print ip except:
pass thread_all = []
for i in range(100): #根据情况决定 t = Thread(target=verify_ip)
thread_all.append(t)
t.start() for t in thread_all:
t.join() get_ip.close()

python验证代理IP的更多相关文章

  1. python检验代理ip是否可用、代理ip检验

    python检验代理ip是否可用.代理ip检验 安装相关模块: pip install requests 验证代理IP是否可用脚本: import random import telnetlib im ...

  2. 【原创】验证代理IP是否有用

    /// <summary> /// 验证代理IP是否有用 /// </summary> /// <param name="ip">IP地址< ...

  3. Python 快速验证代理IP是否有效

    有时候,我们需要用到代理IP,比如在爬虫的时候,但是得到了IP之后,可能不知道怎么验证这些IP是不是有效的,这时候我们可以使用Python携带该IP来模拟访问某一个网站,如果多次未成功访问,则说明这个 ...

  4. Python爬虫代理IP池

    目录[-] 1.问题 2.代理池设计 3.代码模块 4.安装 5.使用 6.最后 在公司做分布式深网爬虫,搭建了一套稳定的代理池服务,为上千个爬虫提供有效的代理,保证各个爬虫拿到的都是对应网站有效的代 ...

  5. python使用代理ip发送http请求

    一.需求背景 网站刷票时,经常会遇到限制一个ip只能投票一次的限制,为此需要使用代理ip 二.脚本如下: 1.Proxy_http.py使用代理ip发送httpr的get和post请求 #coding ...

  6. [python]爬代理ip v2.0(未完待续)

    爬代理ip 所有的代码都放到了我的github上面, HTTP代理常识 HTTP代理按匿名度可分为透明代理.匿名代理和高度匿名代理. 特别感谢:勤奋的小孩 在评论中指出我文章中的错误. REMOTE_ ...

  7. python使用代理ip

    python使用代理的方法有两种 1. #先创建代理ip对象 proxy_support = urllib.request.ProxyHandler({'https':'117.64.149.137: ...

  8. python测试代理IP地址

    代码: # -*- coding: utf-8 -*- import urllib,urllib2,re from random import choice from scrapy.selector ...

  9. 验证代理IP

    ##author:wuhao#import urllib.requestfrom http import cookiejar import xlrd import threading #有效的代理,可 ...

随机推荐

  1. English trip V1 - B 1. How much is it? 它是多少钱? Teacher:Corrine Key: is/are

    In this lesson you will learn to ask about prices. 本节课你将学习询问关于价格 课上内容(Lesson) one piece of     two p ...

  2. pytorch backward问题

    pytorch中关于backward的很有意思的一个问题 <https://blog.csdn.net/shiheyingzhe/article/details/83054238> 但是我 ...

  3. Python安装第三方库,报错超时: Read timed out.

    1.安装beautifulsoup4 >pip install beautifulsoup4 报错超时: Read timed out. 2.解决办法:pip --default-timeout ...

  4. spring boot(十四)shiro登录认证与权限管理

    这篇文章我们来学习如何使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉及到这方面的需求.在Java领域一般有Spring Security ...

  5. python 小练习2

    给你一个整数列表L,判断L中是否存在相同的数字, 若存在,输出YES,否则输出NO.解1l=[]for i in L:    if L.count(i) != 1:        print('YES ...

  6. sql语句的各种模糊查询语句

    一般模糊语句如下: SELECT 字段 FROM 表 WHERE 某字段 Like 条件 其中关于条件,SQL提供了四种匹配模式: 1.%:表示任意0个或多个字符.可匹配任意类型和长度的字符,有些情况 ...

  7. PostgreSQL数据库单机扩展为流复制

    primary:10.189.102.118 standby:10.189.100.195 1. 配置ssh互信机制 在primary主库执行 $ ssh-keygen -t rsa $ cp ~/. ...

  8. [NOIP 2015TG D2T3] 运输计划

    题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n-1 条航道连通了 L 国的所有星球. 小 P 掌管一家 ...

  9. 牛客第二场Dmoney

    链接:https://www.nowcoder.com/acm/contest/140/D 来源:牛客网 题目描述 White Cloud has built n stores numbered to ...

  10. 2015-09-29 js2

    Javasript 六. 条件语句 1. 比较运算符 == .!=.>.>=.<.<= 转大/小写:toUpperCase().toLowerCase() 2. 逻辑运算符(与 ...