阅读:3021回复:19
有没有批量抓取并验证而且自动导入到代理的扩展 |
|
1楼#
发布于:2017-02-09 12:45
批量获取from bs4 import BeautifulSoup
import urllib2 of = open('proxy.txt' , 'w') for page in range(1, 160): html_doc = urllib2.urlopen('http://www.xici.net.co/nn/' + str(page) ).read() soup = BeautifulSoup(html_doc) trs = soup.find('table', id='ip_list').find_all('tr') for tr in trs[1:]: tds = tr.find_all('td') ip = tds[1].text.strip() port = tds[2].text.strip() protocol = tds[5].text.strip() if protocol == 'HTTP' or protocol == 'HTTPS': of.write('%s=%s:%s\n' % (protocol, ip, port) ) print '%s=%s:%s' % (protocol, ip, port) of.close() |
|
2楼#
发布于:2017-02-09 12:46
接着验证代理是否可用#encoding=gbk
import httplib import time import urllib import threading inFile = open('proxy.txt', 'r') outFile = open('available.txt', 'w') lock = threading.Lock() def test(): while True: lock.acquire() line = inFile.readline().strip() lock.release() if len(line) == 0: break protocol, proxy = line.split('=') headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Cookie': ''} try: conn = httplib.HTTPConnection(proxy, timeout=3.0) conn.request(method='POST', url='http://e.meituan.com/m/account/login', body='login=ttttttttttttttttttttttttttttttttttttt&password=bb&remember_username=1&auto_login=1', headers=headers ) res = conn.getresponse() ret_headers = str( res.getheaders() ) html_doc = res.read().decode('utf-8') print html_doc.encode('gbk') if ret_headers.find(u'/m/account/login/') > 0: lock.acquire() print 'add proxy', proxy outFile.write(proxy + '\n') lock.release() else: print '.', except Exception, e: print e all_thread = [] for i in range(50): t = threading.Thread(target=test) all_thread.append(t) t.start() for t in all_thread: t.join() inFile.close() outFile.close() |
|
3楼#
发布于:2017-02-09 12:48
|
|
4楼#
发布于:2017-02-09 12:52
|
|
5楼#
发布于:2017-02-09 15:16
|
|
6楼#
发布于:2017-02-09 15:16
|
|
7楼#
发布于:2017-02-09 18:09
python 代码,要安装 Python运行环境
如果是Windows不想装,可以改写为 powershell 代码 |
|
|
8楼#
发布于:2017-02-10 06:59
安装了python可是http://www.jb51.net/article/90783.htm这里的代码运行后无反应呀
|
|
9楼#
发布于:2017-02-10 18:31
找到一个https://github.com/nladuo/AutoShadowsocks但是这个模块怎么加入到里面呢。请傻瓜教程
|
|
10楼#
发布于:2017-02-10 20:45
不知底细的代理也敢用,看来你真不把自己的账号密码当回事。
|
|
11楼#
发布于:2017-02-10 20:47
warb:找到一个https://github.com/nladuo/AutoShadowsocks但是这个模块怎么加入到里面呢。请傻瓜教程回到原帖https://www.visualstudio.com/downloads/ 下载Visual Studio,用其打开AutoShadowsocks.sln文件,进行编译 |
|
12楼#
发布于:2017-02-11 07:54
|
|
13楼#
发布于:2017-02-11 11:41
大家看看http://www.jb51.net/article/90783.htm这里的脚本复制后放到python里面回车后不能运行。
|
|
14楼#
发布于:2017-02-14 07:54
不错,总算从你的帖子里找到了点有用的东西。看国内的一些视频需要用。反正没那些视频网站的账号,他们拿到我的cookies也没什么问题………………………………吧。
![]() |
|
上一页
下一页