工作任务:批量下载东方财富choice中的创投数据
在ChatGPT中输入提示词:
你是一个Python编程专家,写一个关于键盘鼠标自动化操作的Python脚本,具体步骤如下:
打开东方财富choice软件,软件路径为:"D:\Program Files (x86)\Eastmoney\Choice\ChoiceLoader.exe"
暂停20秒,等待程序加载;
鼠标左键点击坐标:254, 16;(注释:股票)
暂停5秒,等待程序加载;
鼠标左键点击坐标:308, 331;(注释:专项应用)
暂停5秒,等待程序加载;
鼠标左键点击坐标:472, 472;(注释:创投数据)
暂停5秒,等待程序加载;
鼠标左键点击坐标:1293, 942;(注释:每页)
暂停5秒,等待程序加载;
鼠标左键点击坐标:1270,897;(注释:100条/每页)
暂停5秒,等待程序加载;
循环执行下面【】里面的步骤15次:
【鼠标左键点击坐标:1841, 168;(注释:导出Excel)
暂停10秒,等待程序加载;
鼠标左键点击坐标:864, 477;(注释:文件名)
暂停5秒,等待程序加载;
键盘输入数字:{number}({number}的值从1开始,以1递增,到15结束)
暂停5秒,等待程序加载;
鼠标左键点击坐标:1125, 618;(注释:保存Excel文件到电脑)
暂停10秒,等待程序加载;
用pyautogui库检查当前页面的区域(左上角坐标是:1114,881,右下角坐标是:1296,969)是否和图片""F:\aivideo\next.jpg""一致的按钮,pyautogui.locateOnScreen函数的参数confidence为0.8,如果有,就模拟鼠标左键点击;(注释:点击下一页)
按下回车键;
暂停5秒,等待程序加载;】
关闭东方财富choice软件;
注意:每一步动作都输出信息到屏幕上
Python源代码如下:
import pyautogui
import time
import subprocess
def open_program(path):
print(f"Opening program: {path}")
subprocess.Popen(path)
time.sleep(20) # Pause to wait for the program to load
def click_at(x, y, description):
print(f"Clicking at ({x}, {y}) - {description}")
pyautogui.click(x, y)
time.sleep(5) # Pause to wait for the action to complete
def type_text(text):
print(f"Typing text: {text}")
pyautogui.typewrite(str(text))
time.sleep(5) # Pause to wait for the typing to complete
def press_enter():
print("Pressing Enter key")
pyautogui.press('enter')
time.sleep(5) # Pause to wait for the action to complete
def check_and_click_image(image_path, region):
print(f"Checking for image: {image_path} in region: {region}")
location = pyautogui.locateOnScreen(image_path, confidence=0.8, region=region)
if location is not None:
print("Image found, clicking on it.")
pyautogui.click(location)
time.sleep(5) # Pause to wait for the action to complete
else:
print("Image not found.")
def main():
program_path = "D:\\Program Files (x86)\\Eastmoney\\Choice\\ChoiceLoader.exe"
open_program(program_path)
click_at(254, 16, "股票")
click_at(308, 331, "专项应用")
click_at(472, 472, "创投数据")
click_at(1293, 942, "每页")
click_at(1270, 897, "100条/每页")
for number in range(1, 16):
click_at(1841, 168, "导出Excel")
time.sleep(10) # Extra wait for export dialog
click_at(864, 477, "文件名")
type_text(number)
click_at(1125, 618, "保存Excel文件到电脑")
time.sleep(10) # Extra wait for save action
check_and_click_image("F:\\aivideo\\next.jpg", region=(1114, 881, 182, 88))
press_enter()
print("Closing the program.")
pyautogui.hotkey('alt', 'f4')
if __name__ == "__main__":
main()