Problem of analog login Taobao slider

Preface

Recently, it has been found that Taobao's cookie s on the server are always in the state of not being logged in. When Taobao logs in, it will force a slider. Moreover, by simulating the slider, it will always prompt:

< div id = "nocaptcha" class = "NC container TB login" data NC IDX = "1" style = "display: block;" >
It seems that Taobao has made some judgments on the behavior of simulated Login and cookie grabbing

Test code

#!/usr/bin/python
#-*-coding:utf-8-*-
from selenium import webdriver  
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import urllib2
import json
import sys
#dcap = dict(DesiredCapabilities.PHANTOMJS)
#dcap["phantomjs.page.settings.userAgent"] = (
#    "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
#)
#driver = webdriver.PhantomJS(executable_path='/home/sevencm/phantomjs/bin/phantomjs',desired_capabilities=dcap)  
#profiledir='/home/sevencm/.mozilla/firefox/miinxjat.default'
#profile=webdriver.FirefoxProfile(profiledir)
#option=webdriver.ChromeOptions()
#option.add_argument('--user-data-dir=/home/sevencm/.config/google-chrome/Default')
driver = webdriver.Chrome()  
#driver.viewportSize={'width':1024,'height':800}
#driver.maximize_window()
 
#driver.delete_all_cookies()
driver.get("https://login.taobao.com/member/login.jhtml?from=taobaoindex&f=top&style=&sub=true&redirect_url=https%3A%2F%2Fmyseller.taobao.com%2Fseller_admin.htm")
 #load the switch
element=WebDriverWait(driver,60).until(lambda driver : driver.find_element_by_xpath("//*[@id='J_Quick2Static']"))
element.click()
driver.implicitly_wait(20)
sleep(1)
username=driver.find_element_by_name("TPL_username")
if not username.is_displayed:
    driver.implicitly_wait(20)
    driver.find_element_by_xpath("//*[@id='J_Quick2Static']").click()
driver.implicitly_wait(20)
sleep(2)
username.send_keys(u'xxxx')
username.send_keys(Keys.TAB)
driver.implicitly_wait(20)
sleep(2)
pwc=driver.find_element_by_name("TPL_password")
pwc.send_keys("xxxxx")
sleep(1)
driver.save_screenshot('login-screeshot-1.png')
sleep(2)
while True:
    try:
        #Position slider element, if not present, skip loop
        show=driver.find_element_by_xpath("//*[@id='nocaptcha']")
    showval=show.value_of_css_property("display")
        if not show.is_displayed():
            break        
        source=driver.find_element_by_xpath("//*[@id='nc_1_n1z']")  
    sleep(3)
        #Define mouse drag and drop actions
        #ActionChains(driver).drag_and_drop_by_offset(source,400,0).perform()
        #driver.save_screenshot('login-screeshot-11.png')
    action = ActionChains(driver)
    sleep(1)
    action.click_and_hold(source).perform()
    for index in range(20):
      try:
         action.move_by_offset(2, 0).perform() #Move the mouse in parallel
         driver.save_screenshot('login-screeshot-i-'+str(index)+'.png')
      except Exception as e:
         print(e) 
         break
      if(index==19):
       action.release()
       sleep(1)
       driver.save_screenshot('login-screeshot-i-'+str(index)+'.png')
      else: 
       sleep(0.01) #Waiting pause time
        sleep(0.1)
    print(show.get_attribute("outerHTML"))
    sleep(2)
    driver.save_screenshot('login-screeshot-0.png')
        #Check whether the authentication is successful. Get the text value / / * [@ id = "NC ﹣ 1 ﹣ scale ﹣ text"] / span
    text=driver.find_element_by_xpath("//*[@id='nc_1__scale_text']/span")
    if text.text.startswith(u'Verification passed'):
        print('Slide successfully')
        break
    if text.text.startswith(u'Please click'):
        print('Slide successfully')
        break
    if text.text.startswith(u'Please press and hold'):
        continue
    except Exception as e:
    print(e) 
        driver.find_element_by_xpath("//div[@id='nocaptcha']/div/span/a").click()
driver.find_element_by_xpath("//*[@id='J_SubmitStatic']").click()
sleep(2)
driver.save_screenshot('login-screeshot-2.png')
#Here is the code to get the cookie
cookie = [item["name"] + "=" + item["value"] for item in driver.get_cookies()]
cookiestr = ';'.join(item for item in cookie)
#print cookiestr
data={
'cookie':cookiestr
}
print(data)
#post cookie to interface
try:
    headers = {'Content-Type': 'application/json'}
    request = urllib2.Request(url='http://127.0.0.1:8080/update/taobao/cookie', headers=headers, data=json.dumps(data))
    response = urllib2.urlopen(request)
    print(response.read())
except Exception as e:
    print(e) 
driver.close()
driver.quit()
sys.exit(0)
total.gif

Solutions

Put the simulated login into windows system, use Firefox driver, and request through IP proxy of server

Tags: Selenium JSON Windows Firefox

Posted on Mon, 04 May 2020 13:16:15 -0700 by CallItKarma