python selenium鼠标滑动操作

 

 

 

 

 

先安装pyautogui:

pip install pyautogui

#coding=utf-8

import pyautogui

from selenium import webdriver

from time import sleep

dr = webdriver.Chrome()

def size():

   x=dr.get_window_size()["width"]#获取当前屏幕的宽

   y=dr.get_window_size()["height"]#获取当前屏幕的高

   return (x,y)

#左滑

def left():

   sz=size()

   x1=int(sz[0]*0.9)

   x2=int(sz[0]*1.3)

   y1=int(sz[1]*1.2)

   pyautogui.click(x1,y1,button='left')

   pyautogui.mouseDown()

   pyautogui.moveTo(x2,y1,duration=0.25)

   pyautogui.mouseUp()

   sleep(1)

dr.get("https://shopcs.yunyoute.com/login")

dr.maximize_window()

sleep(2)

left()

  

posted @ 2019-11-23 16:32  佛系程序员  阅读(1915)  评论(0编辑  收藏  举报