帝王谷资源网 Design By www.wdxyy.com
由于时间原因,有时候可能会错过某个上网课的时间段。因此想要实现自动定时启动DingDing。
新手一枚,如有不当勿喷望大佬指正。
自动打开DingDing可以由两种方法实现:
- 通过找出找出软件在电脑中快捷方式的位置(电脑屏幕中的坐标),使用代码模拟鼠标进行双击打开。
- 通过输入软件在电脑中的安装路径打开软件。
1.第一种方法:
"htmlcode">
import pyautogui import time #循环执行pyautogui.position()获取不同位置坐标 while True: print("当前鼠标的坐标为:"pyautogui.position()) time.sleep(1)#设置打印的时间间隔
多次执行结果:
在使用此方法获取到想要打开的软件的快捷方式后,就是进行鼠标点击的模拟了
我们可以通过使用pyautogui.click(click=2)实现双击鼠标左键的效果。
通使用pyautogui.moveTo(x,y)实现鼠标的移动功能。结合鼠标的点击就可以进行自动的打开电脑应用的功能了。
import pyautogui import time def AutoOpen(): startPosition = (327,164)#鼠标需要移动的位置 endPosition = (306,216) position=[startPosition,endPosition] for i in position: pyautogui.moveTo(i)#控制鼠标移动 pyautogui.click(clicks=2)#实现鼠标双击 time.sleep(3) if __name__ == '__main__': AutoOpen()
需要注意的是:本方法不能再代码的编译器占满整个屏幕的时候使用,那样获取的坐标位置为编译器中的位置,位置虽然通用,但是不能实现点击应用的功能,要点击的应用不能被编译器所覆盖。只有这样才能实现点击功能。
2.第二种方法
获取文件的安装路径,找到后缀为.exe的可执行的文件,使用os.startfile(Path)打开文件(os库为自带库无需安装)Path=“F:\XXX\XXX.exe”
import os Path = r'F:\DingDing\DingtalkLauncher.exe' os.startfile(Path)
通过上面三行代码足以打开需要打开的文件。
import pyautogui import time import os def AutoOpen(Path): os.startfile(Path) #os.startfile()打开外部应该程序,与windows双击相同 pyautogui.moveTo(306, 216)#pyautogui.moveTo()将鼠标移动到指定位置 time.sleep(6) pyautogui.click(clicks=2)#鼠标点击,实现鼠标双击 if __name__ == '__main__': Path=r'F:\DingDing\DingtalkLauncher.exe' AutoOpen()
此方法如果不涉及点击事件的模拟则没有要求,如果需要点击则同上,不能覆盖住要点击的位置。
3.定时打开
在自动打开的功能实现后,就是简单的设置自动打开的时间了,通过使用time 库,获取当前时间。自己可以设置一个需要打开的时间,通过对比当前时间就能实现定时自动打开的功能了。
完整代码:
import pyautogui import time def open_app(Path): os.startfile(Path) #os.startfile()打开外部应该程序,与windows双击相同 pyautogui.moveTo(306, 216)#pyautogui.moveTo()将鼠标移动到指定位置 time.sleep(6) pyautogui.click(clicks=2)#鼠标点击,实现鼠标双击 def AutoOpen(): startPosition = (327,164) endPosition = (306,216) position=[startPosition,endPosition] for i in position: pyautogui.moveTo(i) pyautogui.click(clicks=2) time.sleep(3) if __name__ == '__main__': Path=r'F:\DingDing\DingtalkLauncher.exe' times = "2020-xx-xx xx:xx"#设置需要打开的时间,此时间看自己需求是否精确到秒("2020-xx-xx xx:xx:xx") while True: nowtime = time.strftime('%Y-%m-%d %H:%M') if (times == nowtime): open_app(Path) break else: print(time.strftime('%Y-%m-%d %H:%M:%S')) time.sleep(10)
python自动化打开网页
from selenium.webdriver.firefox.options import Options as FOptions from selenium.webdriver.chrome.options import Options as Foptions from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.firefox.firefox_profile import FirefoxProfile #firefox设置代理 profile = FirefoxProfile() # 激活手动代理配置(对应着在 profile(配置文件)中设置首选项) profile.set_preference("network.proxy.type", 1) # ip及其端口号配置为 http 协议代理 profile.set_preference("network.proxy.http", "127.0.0.1") profile.set_preference("network.proxy.http_port", 8080) # 所有协议共用一种 ip 及端口,如果单独配置,不必设置该项,因为其默认为 False profile.set_preference("network.proxy.share_proxy_settings", True) #chrome设置代理 # options = FOptions() options = FOptions() chrome_options = webdriver.FirefoxOptions() chrome_options.add_argument('--proxy-server=http://127.0.0.1:8080') chrome_options.add_argument('--ignore-certificate-errors') chrome_options.add_argument('disable-infobars') browser = webdriver.Firefox(executable_path="D:/geckodriver.exe",firefox_profile=profile) browser.maximize_window() browser.get('https://account.dianping.com/login?redir=http%3A%2F%2Fwww.dianping.com%2F') button = browser.find_element_by_xpath('/html/body/div/div[2]/div[5]/span') button.click()
帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com
暂无评论...
更新日志
2024年10月25日
2024年10月25日
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限量版][WAV整轨]
- 林育群.2013-BalladShow(日本版)【环球】【WAV+CUE】
- 陈加洛.1992-痛到感觉不到【宝丽金】【WAV+CUE】
- 群星.2023-宿命之敌电视剧原声带【韶愔音乐】【FLAC分轨】
- 東京事変-大発見[FLAC+CUE]
- 椎名林檎-三文ゴシップ[FLAC+CUE]
- 2024年08月04日
- 裘德《裘德「最后的水族馆」演唱会LIVE》[320K/MP3][228.89MB]
- 裘德《裘德「最后的水族馆」演唱会LIVE》[24bit 48kHz][FLAC/分轨][2.08G]
- 基因三重奏《如果你什么都不说 音乐会现场录音》[320K/MP3][145.37MB]
- 孟庭苇.1996-月亮说话(2020环球24KGOLD限量版)【上华】【WAV+CUE】
- 群星.1997-新艺宝优质音响系列·国语精选监听版【新艺宝】【WAV+CUE】
- 阿桑.2005-寂寞在唱歌(星外星引进版)【华研国际】【WAV+CUE】
- 基因三重奏《如果你什么都不说 音乐会现场录音》[FLAC/分轨][287.43MB]
- 蔡题谦《我爱你,却依然要看你走》[320K/MP3][88.65MB]