This is

specific code share Taobao python2.7+selenium2 to achieve automatic slide certification, for your reference, the specific contents are as follows

1.

compiler environment operating system: win7; python2.7+selenium2; ide:pycharm; language: Browser: IE10, chrome

2.1

the accident began today when I found it in Taobao login password forgot. Select the password when Taobao actually added a slider certification.

" happens to be learning by herself, and wants to try whether it can automatically drag the slider.

2.2

Baidu find not much because of their own ideas, the first choice is to ask Baidu, finally found an article, this article uses C# to achieve the function, and the need to coordinate mentioned positioning block elements in the web and the desktop , and this function can be used directly for the elements in the selenium interface to fix , then the rest of the last question is how to know the displacement of the slider. (forgive me forget the name)

2.3

began to test everyone in the manual operation will be found if the slider slider displacement enough, it will automatically restore the trigger cannot be successfully authenticated links, so I use a stupid method to move the operation at first. Press F12 to open the browser, get the code as follows:

here to write the picture description

here to write the picture description

about now clear right displacement of 300px, OK began to write code, after many times of test to determine the slider move after three cases:

1 no response: please press slider, drag it to the right;
2 failure: Oh, failed to load, please click to refresh the page
3 success: Please click map XX please enter a word, XX < /strong> below

solution: no need to repeat the response, drag the slider, until success; failure, need to automatically click the refresh button, the slider to no response state; succeed, temporarily directly from the browser, the study of captcha recognition still, after completion.

2.4 complete code

PS: paste up the code, I do not know how to align, if you directly copy the operation, you may report wrong, please modify it automatically.

 encoding=utf-8 selenium import webdriver # from from selenium.webdriver.common.action_chains import ActionChains import time # using Google browser, easy to see the effect, if the pursuit of speed can be used phantomJS driver=webdriver.Chrome (#) to adjust the maximum window, otherwise some elements cannot display (driver.maximize_window) # using Taobao password interface test driver.get ('https://passport.taobao.com/ac/password_find.htm? Time.sleep (spm=a2107.1.0.0.phBxhD& from_site=0') 5) # for sliding module and other JS files loaded! While True: try: # positioning slider element source=driver.find_element_by_xpath ("//*[@id='nc_1_n1z']") # definition of drag and drop action ActionChains (driver).Drag_and_drop_by_offset (source, 400,0).Perform (JS) # for authentication operation, if the range to be easy error time.sleep (2) # see if authentication is successful, to obtain the text value text=driver.find_element_by_xpath ("//div[@id='nc_1__scale_text']/span") # at present, only had 3 cases: success (please enter the verification code, please click below in Figure); no response (press and hold the slider); failure (oh, failed, please refresh the if (U'text.text.startswith) please below: Print (' ') successful' break if text.text.startswith Journal (U') please click on the' (print): 'successful' sliding) break If text.text.startswith (U'press'): continue except Exception as e: refresh button # here after failure, reload the slider module driver.find_element_by_xpath ("//div[@id='havana_nco']/div/span/a") (.Click) print (E) # exit the browser, if the browser to open multiple windows, you can use the driver.close () to close the current window instead of closing the browser driver.quit (

) all above is the article, hope to help everyone to learn, I hope you will support a script.

This paper fixed link:http://www.script-home.com/python2-7selenium2-automatically-authenticate-taobao-slider.html | Script Home | +Copy Link

Article reprint please specify:Python2.7+selenium2 automatically authenticate Taobao slider | Script Home

You may also be interested in these articles!