批量獲取及驗證HTTP代理的Python腳本
1. 在掃號人人網(wǎng)時,我遇到單個賬號錯誤兩次,強制要求輸入驗證碼,而對方并未實施IP策略。
我采用維護10萬(用戶名,密碼) 隊列的方式來繞過驗證碼。具體的做法是,當某個用戶名、密碼組合遇到需要驗證碼,就把該破解序列掛起,放到隊列尾部等待下次測試,繼續(xù)破解其他賬號密碼。
這樣就可以保證2/3的時間都在進行正常破解和掃號。
2. 在破解美團網(wǎng)某系統(tǒng)賬號時,我遇到了單個IP訪問有一定限制,請求頻率不可過快。于是我掛了72個 HTTP代理來解決這個問題。 看似每個IP的請求都正常,但其實從整個程序上看,效率還是挺可觀的。
本篇我發(fā)出自己抓HTTP的腳本片段,其實只有幾行。匿名代理是從這里抓取的:http://www.xici.net.co/nn/
首先獲取代理列表 :
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()接著驗證代理是否可用,因為我是用于破解美團網(wǎng)系統(tǒng)的賬號,因此用了美團的頁面標記:
#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()相關文章
python中利用隊列asyncio.Queue進行通訊詳解
asyncio是Python 3.4版本引入的標準庫,直接內置了對異步IO的支持。 下面這篇文章主要給大家介紹了關于python中利用隊列asyncio.Queue進行通訊的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下。2017-09-09
Django框架會話技術實例分析【Cookie與Session】
這篇文章主要介紹了Django框架會話技術,結合實例形式分析了Django框架Cookie與Session相關使用技巧與注意事項,需要的朋友可以參考下2019-05-05
Python3實戰(zhàn)之爬蟲抓取網(wǎng)易云音樂的熱門評論
這篇文章主要給大家介紹了關于Python3實戰(zhàn)之爬蟲抓取網(wǎng)易云音樂熱評的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。2017-10-10

