Check the landing problem with simulated sky eye

I believe that a lot of little friends who are crawlers will encounter a lot of problems with the slider verification code. It is required to log in when climbing the sky eye. Can the slider verification code of Tianyan check be solved? The answer must be yes. Today, we will talk about the solution of the slider verification code like Tianyan check.

There are several steps to solve the slider verification code. First: screenshot. Through various technical means, the target graph is as follows:

Code implementation fragment:

button = driver.find_element_by_xpath('/html/body/div[10]/div[2]/div[2]/div[2]/div[2]')

ActionChains(driver).move_to_element(button).click_and_hold().perform()

image_node = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[10]/div[2]/div[2]/div[1]/div[2]/div[1]/a[2]/div[1]')))

left = image_node.location["x"]

top = image_node.location["y"]

element_width = image_node.location["x"] + image_node.size['width']

element_height = image_node.location["y"] + image_node.size['height']

driver.save_screenshot("./tianyancha.png")

Principle: drag the slider to make the gap appear, locate the image element, and take a screenshot through the position and size of the image. The screenshot is as follows

Step 2: calculate the sliding distance
The code is as follows:


def return_distance():

"""

//Calculate the sliding distance according to the intercepted captcha picture

"""

    print("call return_distance Method-----------------------")

img = Image.open("./yanzhengma.png")

weight, height = img.size

for iin range(65, weight):

for jin range(height):

img = img.convert('RGB')

str_strlist = img.load()

data = str_strlist[i, j]

a, b, c = data

if ain list(range(10))and bin list(range(60, 80)):

print("Return value-------------")

return i -6


Step 3: design the sliding track. There are many middle sliding root tracks on the Internet. Here I also refer to others' tracks. The effect is good.
The code is as follows:

def get_track(self, distance):

"""

//Calculate the moving track according to the offset and manual operation simulation

    :paramdistance: Offset

    :return: Moving trajectory

"""

    # Moving trajectory

    tracks = []

# Current displacement

    current =0

    # Deceleration threshold

    mid = distance *4 /5

    # time interval

# t = 0.2

    t =0.2

    # Initial velocity

    v =0

    while current < distance:

if current < mid:

# a = random.uniform(3, 7)

            a = random.uniform(2, 5)

else:

a = -(random.uniform(12.5, 13.5))

# a = -(random.uniform(12.5, 13.5))

        v0 = v

v = v0 + a * t

x = v0 * t +1 /2 * a * t * t

current += x

if 0.6 < current - distance <1:

x = x -0.53

            tracks.append(round(x, 2))

elif 1 < current - distance <1.5:

x = x -1.4

            tracks.append(round(x, 2))

elif 1.5 < current - distance <3:

x = x -1.8

            tracks.append(round(x, 2))

else:

tracks.append(round(x, 2))

return tracks

Finally: get the sliding handle and simulate the sliding

def move_to_gap(self, slider, tracks):

"""

//Move slider to offset

    :paramslider: slider

    :paramtracks: Moving trajectory

    :return:

"""

    action = ActionChains(self.browser)

action.click_and_hold(slider).perform()

for xin tracks:

# time.sleep(random.randrange(20, 40) / 200)

        action.move_by_offset(xoffset=x,yoffset=-1).perform()

action = ActionChains(self.browser)

time.sleep(2)

action.release().perform()

# print(self.browser.current_window_handle)

Keywords: Fragment

Added by comicrage on Sat, 23 Nov 2019 21:09:58 +0200