import
os
import
cv2
import
time
import
random
import
requests
import
numpy as np
from
selenium
import
webdriver
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.chrome.service
import
Service
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.common.action_chains
import
ActionChains
from
selenium.webdriver.support
import
expected_conditions as EC
ImgLocation
=
'img_location'
def
requests_ip():
[
/
align][align
=
left]
res
=
requests.get('')[
/
align][align
=
left]
print
(res.text)
return
res.text
def
save_yzm(driver):
if
not
os.path.exists(ImgLocation):
os.mkdir(ImgLocation)
bg_img
=
driver.find_element(By.XPATH,
'//*[@id="ISDCaptcha"]/div/div[1]/div[4]/div[1]/div[2]/div/div/div[1]/div[2]'
).get_attribute(
'style'
)
puzzle_img
=
driver.find_element(By.XPATH,
'//*[@id="ISDCaptcha"]/div/div[1]/div[4]/div[1]/div[2]/div/div/div[1]/div[1]/div[1]'
).get_attribute(
'style'
)
img_url
=
bg_img.split(
)[
1
]
proxy
=
{
"http"
: "",
"https"
: ""
}
content
=
requests.get(img_url, proxies
=
proxy).content
with
open
(f
'./{ImgLocation}/bgImgUrl.png'
,
'wb'
) as f:
f.write(content)
content1
=
requests.get(puzzle_url, proxies
=
proxy).content
with
open
(f
'./{ImgLocation}/puzzleImgUrl.png'
,
'wb'
) as f:
f.write(content1)
def
find_puzzle(bg_img_path
=
f
'./{ImgLocation}/bgImgUrl.png'
, puzzle_img_path
=
f
'./{ImgLocation}/puzzleImgUrl.png'
):
img
=
cv2.imdecode(np.fromfile(bg_img_path, dtype
=
np.uint8), cv2.IMREAD_COLOR)
tpl
=
cv2.imdecode(np.fromfile(puzzle_img_path, dtype
=
np.uint8), cv2.IMREAD_COLOR)
img_gry
=
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_, img_bw
=
cv2.threshold(img_gry,
127
,
255
, cv2.THRESH_BINARY)
tpl
=
cv2.cvtColor(tpl, cv2.COLOR_BGR2GRAY)
for
row
in
range
(tpl.shape[
0
]):
for
col
in
range
(tpl.shape[
1
]):
if
tpl[row, col]
=
=
0
:
tpl[row, col]
=
96
lower
=
np.array([
96
])
upper
=
np.array([
96
])
mask
=
cv2.inRange(tpl, lower, upper)
tpl[mask
=
=
0
]
=
0
tpl[mask !
=
0
]
=
255
result
=
cv2.matchTemplate(img_bw, tpl, cv2.TM_CCOEFF_NORMED)
_, _, _, max_loc
=
cv2.minMaxLoc(result)
distance
=
int
(max_loc[
0
]
*
0.8245
)
+
random.randint(
1
,
3
)
return
distance
def
generate_track(distance):
ratio
=
distance
/
126
new_track
=
[]
base_track
=
[
'29,11,0'
,
'29,11,11'
,
'29,11,26'
,
'33,11,56'
,
'34,11,66'
,
'36,11,67'
,
'39,11,76'
,
'41,11,83'
,
'43,11,86'
,
'46,11,92'
,
'49,11,98'
,
'50,11,102'
,
'52,11,106'
,
'53,11,111'
,
'55,11,116'
,
'57,11,118'
,
'59,11,123'
,
'60,11,126'
,
'62,11,132'
,
'64,12,134'
,
'65,12,138'
,
'66,12,142'
,
'68,12,148'
,
'69,12,151'
,
'70,13,155'
,
'71,13,158'
,
'72,13,164'
,
'74,13,166'
,
'75,13,170'
,
'76,14,174'
,
'77,14,180'
,
'79,14,182'
,
'81,14,186'
,
'82,14,196'
,
'84,14,198'
,
'86,14,207'
,
'87,15,212'
,
'89,15,219'
,
'90,15,223'
,
'92,15,230'
,
'93,15,234'
,
'94,15,239'
,
'95,15,243'
,
'98,15,246'
,
'100,15,250'
,
'102,15,260'
,
'105,15,262'
,
'106,15,266'
,
'108,15,270'
,
'109,16,276'
,
'111,16,278'
,
'113,16,283'
,
'115,16,286'
,
'117,16,291'
,
'118,16,294'
,
'119,16,298'
,
'121,16,302'
,
'123,16,309'
,
'124,16,311'
,
'125,16,315'
,
'126,16,319'
,
'129,16,324'
,
'130,16,327'
,
'131,16,331'
,
'132,16,334'
,
'132,16,388'
,
'132,16,522'
,
'133,16,566'
,
'134,16,574'
,
'135,16,575'
,
'136,16,594'
,
'137,16,620'
,
'138,16,625'
,
'139,16,652'
,
'140,16,657'
,
'141,17,676'
,
'141,18,680'
,
'142,18,684'
,
'143,18,688'
,
'144,18,716'
,
'145,18,724'
,
'146,18,796'
,
'147,19,828'
,
'148,19,860'
,
'149,19,888'
,
'149,19,890'
,
'150,19,916'
,
'151,20,932'
,
'152,20,936'
,
'152,20,1021'
,
'153,20,1150'
,
'154,20,1152'
,
'155,20,1236'
,
'155,20,1388'
,
'155,20,1522'
,
'155,20,1717'
]
for
track
in
base_track:
t
=
track.split(
","
)
new_track.append((
str
(
int
(
int
(t[
0
])
*
ratio)),
str
(t[
1
]),
str
(
int
(
int
(t[
2
])
*
ratio))))
tracks
=
[(
int
(x),
int
(y),
int
(z))
for
x, y, z
in
new_track]
anjuke_x
=
[x[
0
]
for
x
in
tracks]
anjuke_y
=
[x[
1
]
for
x
in
tracks]
x_list
=
[
0
]
+
[anjuke_x[i]
-
anjuke_x[i
-
1
]
for
i
in
range
(
1
,
len
(anjuke_x))]
y_list
=
[
0
]
+
[anjuke_y[i]
-
anjuke_y[i
-
1
]
for
i
in
range
(
1
,
len
(anjuke_y))]
return
x_list, y_list
def
drag_slider(url):
options
=
webdriver.ChromeOptions()
options.binary_location
=
''
options.add_argument("")
driver
=
webdriver.Chrome(service
=
Service(''),
options
=
options)
driver.maximize_window()
driver.set_page_load_timeout(
10
)
driver.get(url)
wait
=
WebDriverWait(driver,
10
)
wait.until(EC.presence_of_element_located((By.XPATH,
'//*[@id="ISDCaptcha"]/div/div[1]/div[1]'
)))
button
=
driver.find_element(By.XPATH,
'//*[@id="ISDCaptcha"]/div/div[1]/div[1]'
)
button.click()
time.sleep(
2
)
wait.until(EC.presence_of_element_located((By.XPATH,
'//*[@id="ISDCaptcha"]/div/div[1]/div[4]/div[1]/div[2]/div/div/div[2]/div/div[3]'
)))
slider
=
driver.find_element(By.XPATH,
'//*[@id="ISDCaptcha"]/div/div[1]/div[4]/div[1]/div[2]/div/div/div[2]/div/div[3]'
)
action
=
ActionChains(driver,
10
)
action.click_and_hold(slider).perform()
time.sleep(
1
)
save_yzm(driver)
distance
=
find_puzzle()
x_list, y_list
=
generate_track(distance)
for
i, _
in
enumerate
(x_list):
action.move_by_offset(x_list[i], y_list[i]).perform()
time.sleep(
0.5
)
action.release().perform()
time.sleep(
10
)
new_url
=
driver.current_url
print
(
"验证url—直接:"
, url)
print
(
"跳转url—直接:"
, new_url)
if
new_url !
=
url:
return
True
else
:
pass
time.sleep(
2
)
diaoyong(url, driver)
driver.quit()
def
diaoyong(code_url, driver):
wait
=
WebDriverWait(driver,
10
)
wait.until(EC.presence_of_element_located((By.XPATH,
'//*[@id="ISDCaptcha"]/div/div[1]/div[4]/div[1]/div[2]/div/div/div[2]/div/div[3]'
)))
slider
=
driver.find_element(By.XPATH,
'//*[@id="ISDCaptcha"]/div/div[1]/div[4]/div[1]/div[2]/div/div/div[2]/div/div[3]'
)
action
=
ActionChains(driver,
10
)
action.click_and_hold(slider).perform()
time.sleep(
0.5
)
save_yzm(driver)
distance
=
find_puzzle()
x_list, y_list
=
generate_track(distance)
for
i, _
in
enumerate
(x_list):
action.move_by_offset(x_list[i], y_list[i]).perform()
time.sleep(
0.5
)
action.release().perform()
time.sleep(
5
)
new_url
=
driver.current_url
print
(
"验证url—调用:"
, code_url)
print
(
"跳转url—调用:"
, new_url)
if
new_url !
=
code_url:
return
True
else
:
time.sleep(
2
)
diaoyong(code_url, driver)
if
__name__
=
=
'__main__'
:
url
=
""
drag_slider(url)