python维护代理池脚本
来源:互联网 发布:linux u 编辑:程序博客网 时间:2024/05/16 06:21
设计思路:
1.找个免费代理的网站,爬取网站代理ip等信息;
2.验证代理ip是否有用
3.把有用的代理ip信息存到数据库中
import requestsimport MySQLdbfrom bs4 import BeautifulSoupheaders = { 'Host':"map.baidu.com", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Accept-Language": "en-US,en;q=0.5", "Connection": "keep-alive", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"}db = MySQLdb.connect("localhost","root",'liao1234','liao')cursor = db.cursor()sql ="""create table proxies(ip char(20) not null, port char(20), area char(20), nm char(20), type char(20), livetime char(20), ytime char(20))"""cursor.execute(sql)r = requests.get("http://www.xicidaili.com/",headers=headers)html =r.textsoup = BeautifulSoup(html)for tag in soup.find('table',id='ip_list').find_all('tr'): ss = [] for aa in tag.find_all('td'): if aa.string is None: continue else: print aa.string ss.append(aa.string) if len(ss) == 0: continue else: domian = "http://"+str(ss[0])+":"+str(ss[1]) proxies = { "http": domian, "https": domian, } try: r1 = requests.get("http://www.webkaka.com/", proxies=proxies,headers=headers,timeout=5) print r1.status_code if r1.status_code == 200: sql = "insert into proxies(ip,port,area,nm,type,livetime,ytime) values('%s','%s','%s','%s','%s','%s','%s')"%(ss[0].encode('utf-8'),ss[1].encode('utf-8'),ss[2].encode('utf-8'),ss[3].encode('utf-8'),ss[4].encode('utf-8'),ss[5].encode('utf-8'),ss[6].encode('utf-8')) cursor.execute(sql) else: print "code is not 200" except: print "this ip is droped!"db.close
扫描结果如下:
0 0
- python维护代理池脚本
- python爬虫由浅入深15---利用Redis+Flask来维护代理池和Cookie池
- 【Python脚本】-Python查找可用代理IP
- 利用 Flask+Redis 维护 IP 代理池
- 利用 Flask+Redis 维护 IP 代理池
- python 脚本 - 自动检测代理速度
- python 脚本自动切换windows代理设置
- Python代理脚本获取Json数据
- 游戏更新维护serverlist服务器列表替换python脚本
- Python 实现代理池
- Python自动化代理池
- python 代理池
- Python爬虫代理池
- Python构建代理池
- 爬虫基础 -- 用Flask+Redis维护代理池
- 使用Tornado+Redis维护ADSL拨号服务器代理池
- 几个DG维护脚本
- Oracle维护常用脚本
- iOS 滚动视图的复用问题解决方案
- 数组和指针的区别
- 在android studio后遇到Unsupported major.minor version 52.0的处理办法
- CC2541 CC2540 之自定义MAC地址读取
- php + MongoDB + Sphinx 实现全文检索 (二)
- python维护代理池脚本
- HDU5997 rausen loves cakes
- 多米音乐登录注册抓包实验
- C# Task.WhenAll Parallel
- ES运维总结
- 数据结构--学生个人信息管理
- Android通过Mapping文件retrace混淆后的堆栈
- 推荐系统——关联规则
- Spring三种实例化bean的方式