接上一篇保存的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. LeetCode--026--删除排序数组中的重复项

    问题描述: 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成 ...

  2. (Go rails)使用Rescue_from(ActiveSupport:Rescuable::ClassMethods)来解决404(ActiveRecord::RecordNotFound)❌

    https://gorails.com/episodes/handle-404-using-rescue_from?autoplay=1 我的git: https://github.com/chent ...

  3. navicat和 plsql 连接oracle数据库 总结

    打开 navicat  -->工具-->选项-->oci   右侧选择oci.dll 的路径 默认 在 navicat的安装目录下有一个 instantclient 的文件夹 直接选 ...

  4. ml基本问题

    作者:NgShawn 链接:https://www.nowcoder.com/discuss/33737?type=2&order=3&pos=19&page=1 来源:牛客网 ...

  5. Digital Deletions HDU - 1404

    Digital deletions is a two-player game. The rule of the game is as following. Begin by writing down ...

  6. 谈一谈HashMap类

    一.Java中的hashCode()和equals() 1. hashCode()的存在主要是用于查找的快捷性,如Hashtable,HashMap等,hashCode()是用来在散列存储结构中确定对 ...

  7. 如何改变输出方式(让printf输出结果保存到TXT文本中)

    查阅相关资料,汇总如下: #include <stdio.h> #include <stdlib.h> int main() { char money= 's'; char a ...

  8. Visual Studio references中的package找不到

    1. 把solution里面所有project的.net版本设成一样的 2. ERROR: This project references NuGet package(s) that are miss ...

  9. GitHub 简单用法

    1. GitHub账号的申请 首先打开Github主页,https://github.com 如果你没有登录过的话会打开如下图的界面(登录过你就不用看这段了), 注册画面如下: 注意右侧不是登陆界面而 ...

  10. ActiveMQ 到底是推还是拉?

    http://activemq.apache.org/destination-options.html 1. consumer 的配置参数如下图: 配置consumer的示例: public void ...