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 ...
随机推荐
- C# Windows IPSEC监控(仅此一家,别无分店)
Windows IPSEC监控,使用C#编写,输出为一行字符串,可以按照既有IPSEC规则生成模板 using System; using System.Diagnostics; using Syst ...
- 20165228 2017-2018-2 《Java程序设计》第2周学习总结
20165228 2017-2018-2 <Java程序设计>第2周学习总结 教材学习内容总结 标识符:名字 组成:字母/下划线/美元符号或数字 注意:标识符的第一个字符不能是数字字符,且 ...
- pdb的数量限制
Decide How to Configure the CDB --搜索文档 Prepare to create the CDB by research and careful planning. T ...
- Subsequence Count 2017ccpc网络赛 1006 dp+线段树维护矩阵
Problem Description Given a binary string S[1,...,N] (i.e. a sequence of 0's and 1's), and Q queries ...
- url的使用
1.urls.py 默认是在主目录中,主路由配置文件,会包含最基本的地址映射,并且每个地址访问都必须要先经过该文件. 作用:通过 urls中定义好的地址找到对应的视图处理函数 urlpatterns ...
- CentOS7为firewalld添加开放端口及相关操作
1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...
- linux下使用小票打印
linux下使用小票打印 打印机: Xprinter XP-58IIH指令支持: ESC/POS接口: USB, 蓝牙 Linux系统: Centos7 蓝牙配对很快, 配对好后就是连接状态. 但很快 ...
- Thymeleaf基本用法
1.Thymeleaf简介 官方网站:https://www.thymeleaf.org/index.html Thymeleaf是用来开发Web和独立环境项目的现代服务器端Java模板引擎. 2.特 ...
- 《DSP using MATLAB》Problem 6.10
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- hdu3294 Girls' research manacher
One day, sailormoon girls are so delighted that they intend to research about palindromic strings. O ...