資源簡(jiǎn)介
python/selenium 自動(dòng)完成滑塊拼圖驗(yàn)證碼_需要有python2.7.9以上,selenium3.5
代碼片段和文件信息
#?-*-?coding:utf-8?-*-
from?selenium?import?webdriver
from?selenium.webdriver.common.action_chains?import?ActionChains
from?selenium.webdriver.common.keys?import?Keys
import?time
import?os
import?requests
import?hashlib
import?urllib
import?base64
import?json
import?sys
import?win32api
import?win32con
from?PIL?import?Image
from?PIL?import?ImageEnhance
def?pixel_equal(image1?image2?x?y):
????“““
????判斷兩個(gè)像素是否相同
????:param?image1:?圖片1
????:param?image2:?圖片2
????:param?x:?位置x
????:param?y:?位置y
????:return:?像素是否相同
????“““
????#?取兩個(gè)圖片的像素點(diǎn)
????pixel1?=?image1.load()[x?y]
????pixel2?=?image2.load()[x?y]
????threshold?=?60
????if?abs(pixel1[0]?-?pixel2[0])?????????????????????pixel1[2]?-?pixel2[2])?????????return?True
????else:
????????return?False
def?get_gap(image1?image2):
????“““
????獲取缺口偏移量
????:param?image1:?不帶缺口圖片
????:param?image2:?帶缺口圖片
????:return:
????“““
????left?=?0
????for?i?in?range(left?image1.size[0]):
????????for?j?in?range(image1.size[1]):
????????????if?not?pixel_equal(image1?image2?i?j):
????????????????left?=?i
????????????????return?left
????return?left
def?md5str(str):
????m?=?hashlib.md5(str.encode(encoding?=?‘utf-8‘))
????return?m.hexdigest()
def?md5(byte):
????return?hashlib.md5(byte).hexdigest()
class?DamatuApi():
????ID?=?‘50561‘
????KEY?=?‘9ec2ea230a83f411f71c8ae53360251d‘
????HOST?=?‘http://api.dama2.com:7766/app/‘
????def?__init__(self?username??password):
????????self.username?=?username
????????self.password?=?password
????def?getSign(selfparam?=?b‘‘):
????????return?(md5(bytes(self.KEY)+bytes(self.username)?+?param))[:8]
????def?getPwd(self):
????????return?md5str(self.KEY?+?md5str(md5str(self.username)+?md5str(self.password)))
????def?decodeUrl(selfurltype):
????????data?=?{‘a(chǎn)ppID‘:self.ID
????????????????‘user‘:self.username
????????????????‘pwd‘:self.getPwd()
????????????????‘type‘:type
????????????????‘url‘:urllib.quote(url)
????????????????‘sign‘:self.getSign(url.encode(encoding?=?‘utf-8‘))
????????????????}
????????re?=?requests.post(“http://api.dama2.com:7766/app/d2Url“?data?=?(data))
????????jres?=?json.loads(re.text)
????????print?jres
????????Vcode?=?jres[“result“]
????????print?Vcode
????????return?Vcode
????def?deccode(selffilePathtype):
????????f?=?open(filePath?‘rb‘)
????????fdata?=?f.read()
????????filedata?=?base64.b64encode(fdata)
????????f.close()
????????data?=?{‘a(chǎn)ppID‘:?self.ID
????????????????‘user‘:?self.username
????????????????‘pwd‘:?self.getPwd()
????????????????‘type‘:?type
????????????????‘fileDatabase64‘:?filedata
????????????????‘sign‘:?self.getSign(fdata)
????????????????}
????????re?=?requests.post(“http://api.dama2.com:7766/app/d2File“?data?=?(data))
????????jres?=?json.loads(re.text)
????????print?jres
????????Vcode?=?jres[“result“]
????????print?Vco
評(píng)論
共有 條評(píng)論