模拟网页鼠标右键点击

图片保存的一种思路

import pyautogui
# 模拟鼠标右键图片另存为
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.webdriver.common.keys import Keys

from selenium.webdriver.common.by import By

webdriver = webdriver.Chrome()
webdriver.get("https://www.baidu.com")
# 找到图片
img = webdriver.find_element(By.XPATH,'//*[@id="s_lg_img"]')
# 模拟鼠标右键
action = ActionChains(webdriver)
action.move_to_element(img)
# 右键点击
action.context_click(img).key_down(Keys.SHIFT).key_down(Keys.ALT).perform()
# action.perform()
#
# # 模拟鼠标右键图片另存为
pyautogui.typewrite(['down','down','down','down','down','down','down','down','enter'])
#
time.sleep(5)
pyautogui.typewrite(['enter'])
#
time.sleep(5)
webdriver.quit()

原文链接: 模拟网页鼠标右键点击 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( https://gyarmy.com/post-820.html )

发表评论

0则评论给“模拟网页鼠标右键点击”