zoukankan      html  css  js  c++  java
  • python爬虫实践——滑动登陆验证

     1 from selenium import webdriver
     2 from selenium.webdriver import ActionChains
     3 import time
     4 
     5 driver=webdriver.Chrome()
     6 driver.implicitly_wait(10)
     7 driver.get('http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable')
     8 
     9 try:
    10     # 切换到id为iframeResult的窗口内
    11     driver.switch_to.frame('iframeResult')
    12 
    13     #源位置
    14     draggable=driver.find_element_by_id('draggable')
    15 
    16     #目的位置
    17     droppable=driver.find_element_by_id('droppable')
    18     # 调用ActionChains,必须把驱动对象进去
    19     actions=ActionChains(driver)
    20 
    21     # #方式一
    22     # # 瞬间把源图片位置秒移到目标图片位置
    23     # actions.drag_and_drop(draggable,droppable)
    24     # #执行编辑好的行为
    25     # actions.perform()
    26     # time.sleep(5)
    27 
    28     #方式二
    29     source=draggable.location['x']
    30     target=droppable.location['x']
    31     print(source,target)
    32 
    33     distance=target-source
    34     print(distance)
    35 
    36     ActionChains(driver).click_and_hold(draggable).perform()
    37     s=0
    38     while s<distance:
    39         ActionChains(driver).move_by_offset(xoffset=2,yoffset=0).perform()
    40         s+=2
    41 
    42     ActionChains(driver).release().perform()
    43     time.sleep(10)
    44 
    45 finally:
    46     driver.close()
  • 相关阅读:
    线程安全-003-对象锁的同步和异步
    线程安全-002-多个线程多把锁&类锁
    线程安全-001
    FastDFS单节点安装
    Nginx+Keepalived 实现高可用
    linux下配置nginx负载均衡例子
    linux下配置nginx反向代理例子
    Linux命令
    nginx配置文件 nginx.conf 说明
    CentOS安装Nginx 以及日志管理
  • 原文地址:https://www.cnblogs.com/lweiser/p/11048455.html
Copyright © 2011-2022 走看看