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()

猜你喜欢

转载自www.cnblogs.com/Mr-ZY/p/11696693.html
今日推荐