python获取代理IP并测试是否可用
# coding: utf-8 import urllib2
import re
import time def getDL(page):
url = 'http://www.xicidaili.com/nt/{}'.format(page)
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
} req=urllib2.Request(url, headers=header)
res=urllib2.urlopen(req)
html=res.read() srclist=re.findall(r'<tr class=(.|\n)*?<td>(\d+\.\d+\.\d+\.\d+)</td>(.|\n)*?<td>(\d+)</td>(.|\n)*?<td>(HTTP|HTTPS)</td>', html)
xlist = []
for item in srclist:
xlist.append((item[5],item[1],item[3]))
return xlist def testDL(ipstr):
proxy= urllib2.ProxyHandler({'http':"{}:{}".format(ipstr[1], ipstr[2])})
opener=urllib2.build_opener(proxy)
urllib2.install_opener(opener) try:
testUrl = 'http://httpbin.org/ip'
testUrl = 'http://2017.ip138.com/ic.asp'
req=urllib2.Request(testUrl)
res=urllib2.urlopen(req).read()
print "********************* √ {} -- {}".format(ipstr, res) with open("ok.txt","a") as f:
f.write("{} {} {}\n".format(ipstr[0], ipstr[1], ipstr[2]))
f.close()
except Exception as e:
print "******** ×, {} -- {}".format(ipstr, e)
time.sleep(1) def startTask():
for page in xrange(5):
list=getDL(page+1)
for item in list:
testDL(item) if __name__ == '__main__':
startTask()
python获取代理IP并测试是否可用的更多相关文章
- python获取代理IP
利用requests库获取代理,用Beautiful库解析网页筛选ip # -*- coding: utf- -*- import requests from bs4 import Beautiful ...
- Python学习笔记六(免费获取代理IP)
为获取网上免费代理IP,闲的无聊,整合了一下,免费从三个代理网站获取免费代理IP,目的是在某一代理网站被限制时,仍可从可以访问的其他网站上获取代理IP.亲测可用哦!^_^ 仅供大家参考,以下脚本可添 ...
- python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客
python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客 undefined Python多线程抓取代理服务器 | Linux运维笔记 undefined java如 ...
- python爬虫之反爬虫(随机user-agent,获取代理ip,检测代理ip可用性)
python爬虫之反爬虫(随机user-agent,获取代理ip,检测代理ip可用性) 目录 随机User-Agent 获取代理ip 检测代理ip可用性 随机User-Agent fake_usera ...
- 分享一个获取代理ip的python函数
分享一个获取代理ip的python函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #coding:utf-8 from bs4 import Beaut ...
- python检验代理ip是否可用、代理ip检验
python检验代理ip是否可用.代理ip检验 安装相关模块: pip install requests 验证代理IP是否可用脚本: import random import telnetlib im ...
- Python3.x:获取代理ip以及使用
Python3.x:获取代理ip以及使用 python爬虫浏览器伪装 #导入urllib.request模块 import urllib.request #设置请求头 headers=("U ...
- python获取公网ip,本地ip及所在国家城市等相关信息收藏
python获取公网ip的几种方式 from urllib2 import urlopen my_ip = urlopen('http://ip.42.pl/raw').read() ...
- python获取公网ip的几种方式
python获取公网ip的几种方式 转 https://blog.csdn.net/conquerwave/article/details/77666226 from urllib2 import u ...
随机推荐
- diary of laravel
1. 修改数据库连接 初始化数据库: 首先: 修改 config- database.php 中的 数据库链接 其次:修改 .env 中数据库链接 创建表: php artisan migr ...
- HDU 6124 17多校7 Euler theorem(简单思维题)
Problem Description HazelFan is given two positive integers a,b, and he wants to calculate amodb. Bu ...
- 安卓 dex 通用脱壳技术研究(二)
0x03 DexHunter代码分析 DexHunter 实现中,只需要修改一处文件:dalvik\vm\native\dalvik_system_DexFile.cpp 下面是BeyondCompa ...
- 从android设备中提取内核
背景 CVE-2013-2597 是高通 msm_acdb 设备驱动的一个 copy_from_user 栈溢出,利用要用到ROP.f101的漏洞利用介绍中,用到几处Gadgets,显然要根据acdb ...
- Android动态添加Device Admin权限
/********************************************************************** * Android动态添加Device Admin权限 ...
- 【leetcode】14-LongestCommonPrefix
problem Longest Common Prefix 挨个比较每个字符串的元素是否相同,连续对应位置字符都相同,则为共同字符:否则不是. code class Solution { public ...
- Unity 3D-Canvas画布的三种模式
Unity开发VR之Vuforia 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...
- Gym - 101002H: Jewel Thief (背包,分组,DP决策单调性)
pro:给定N,M.输入N个物品,(si,vi)表示第i个物品体积为si,价值为vi,s<=300,vi<=1e9: N<1e6:现在要求,对于背包体积为1到M时,求出最大背包价值. ...
- doc四则运算
import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.ut ...
- HDU 4639 Hehe 2013 Multi-University Training Contest 4
题意大致如下:屌丝找女神聊天,女神回了一句 hehe ,而我们都知道 Hehe 有两个意思,一个就是 Hehe ,另外一个则是 wqnmlgb (我去年买了个表) ,所以屌丝很纠结,于是开始思考到底女 ...