### Terminal Command Line Driver Startup Source: https://github.com/a943512/pyaibote/blob/main/README.md Example command for starting the WebDriver executable via terminal with JSON configuration parameters. ```bash WebDriver.exe "{\"serverIp\":\"127.0.0.1\", \"serverPort\":9999, \"browserName\":\"chrome\", \"debugPort\":0, \"userDataDir\":\"./UserData\", \"browserPath\":\"null\", \"argument\":\"null\", \"extendParam\":\"{'Name':'PyAibote'}\"}" ``` -------------------------------- ### Configure WebDriver and Initialize Web Script Source: https://github.com/a943512/pyaibote/blob/main/README.md Sets up the user data directory and defines the driver parameters for browser automation, followed by script execution. ```python UserDataPath = "C:/AppData" if not os.path.exists(UserDataPath): os.mkdir(UserDataPath) message = { "Action": "Authentication", "Data": { "Token": "PyAibote", } } driver_params = { "browserName": "chrome", "debugPort": 0, "userDataDir": "C:/AppData/PyAibote", "browserPath": None, "argument": None, # 无头模式(后台运行浏览器)启动参数: --headless 浏览器版本大于112 的无头模式:--headless=new,多个启动参数空格隔开,示例: "argument": "--headless=new" "extendParam":f"{message}" } CustomWebScript.execute("0.0.0.0", 9999, Debug=True, Driver_Params=driver_params, Qt=None, WebsocketSwitch=False, WebsocketPort=8888) ``` -------------------------------- ### Create a Custom Web RPA Script Source: https://github.com/a943512/pyaibote/blob/main/README.md Inherit from WebBotMain to define automation logic, configure global settings like logging and implicit waits, and implement the script_main entry point. ```python # 1. 导入 AndoridBotMain 类 # 1. Import the AndoridBotMain class from PyAibote import WebBotMain import time,os # 2. 自定义一个脚本类,继承 WebBotMain # 2. Customize a script class and inherit WebBotMain class CustomWebScript(WebBotMain): # 3. 设置是否终端打印输出 DEBUG :输出, INFO :不输出, 默认打印输出 # 3. Set whether the terminal prints output DEBUG: output, INFO: no output, and print output by default Log_Level = "DEBUG" Websocket_Log_Level = "DEBUG" # 4. 终端打印信息是否存储LOG文件 True: 储存, False:不存储 # 4. Does the terminal print information store the LOG file? True: yes, False: no Log_Storage = True # True # 5. 全局隐式等待 [找不到元素重复查找] # 5. Global implicit wait [repeated search of element not found] # 5.1 元素未加载等待时间(秒) # 5.1 element not loaded wait time (seconds) Implicit_Waiting = 5 # 5.2 元素未加载间隔多少时间重复加载(秒) # 5.2 How often does the element load repeatedly (seconds) Implicit_Waiting_Frequency = 0.5 # 5.3 超过未加载等待时间是否抛出异常 # 5.3 Whether to throw an exception when the waiting time for unloading exceeds Implicit_Waiting_Throwing = False # 6. 注意:此方法是脚本执行入口 # 6. Note: This method is a script execution portal. def script_main(self): result = self.goto("https://baidu.com") print(result) result = self.get_extend_param() result = eval(result) print(type(result)) # 6.1. 显示等待和隐式等待意思一样, 显示等待可以让你在某个局部代码中自定义设置等待时长 # 6.1. Displaying waiting means the same as implicit waiting. Displaying waiting allows you to customize the waiting time in a local code. # StartShowWait函数后的代码按照等待10秒,每个0.5秒重复加载,False找不到不抛出异常,此时你如果设置的全局隐式等待将不生效直到结束显示等待 # StartShowWait function is loaded repeatedly every 0.5 seconds according to the waiting time of 10 seconds. If False is not found, no exception will be thrown. At this time, if you set the global implicit waiting, it will not take effect until the display waiting is over self.StartShowWait(10, 0.5, False) result = self.goto("https://qq.com") print(result) result = self.goto("https://www.hao123.com") print(result) # 6.1 结束显示等待,也是自定义结束局部等待此时如果设置的全局隐式等待后面的代码将按全局隐式等待的设置来执行 # 6.1 Ending display waiting is also a custom ending local waiting. At this time, if the global implicit waiting is set, the code behind it will be executed according to the setting of global implicit waiting self.EndShowWait() # 主函数死循环时web驱动连接断开异常捕获跳出死循环demo示例代码 # while True: # try: # # 死循环中必须加入aibote函数代码 # result = self.get_current_page_id() # print("我是个死循环") # time.sleep(2) # # 服务端捕获客户端断开异常跳出线程循环结束连接 # except OSError as e: # break # # 捕获其他非连接断开异常 # except Exception as e: # print(e) # 关闭驱动 方法一 终端命令杀死驱动 # self.close_driver() # 关闭驱动 方法二 终端命令杀死驱动 # os.popen('taskkill /f /t /im "WebDriver.exe"') # 关闭驱动 方法三 cmd终端直接输入杀死驱动 # taskkill /f /t /im "WebDriver.exe" if __name__ == '__main__': # 7. 启动脚本,监听 9999 号端口, 默认使用 Chrome 浏览器 # 7. Start the script, listen to port 9999, and use Chrome browser by default # 7.1. Debug=True 时,是本地运行脚本,会自动启动 WebDriver.exe 驱动 # 7.1. When debug = true, the script is run locally, and the WebDriver.exe driver will be started automatically # 7.2. 打开终端输入:start chrome.exe --remote-debugging-port=8989 --user-data-dir="C:/AppData/PyAibote" 即可创建一个8989的端口浏览器, # "debugPort" 参数改为8989即可接管浏览器操作,"user-data-dir" 参数为用户目录数据目录,默认是当前目录下的 UserData 文件夹 # 7.2. Open the terminal and enter: start chrome.exe-remote-debugging-port = 8989 to create an 8989 port browser, and change the "debugPort" parameter to 8989 to take over the browser operation # 在远端部署脚本时,请设置 Debug=False,手动启动 WebDriver.exe,启动 WebDriver.exe 时需指定远端 IP 或端口号 # When deploying the script remotely, please set Debug=False to manually start WebDriver.exe, and specify the remote IP or port number when starting WebDriver.exe ``` -------------------------------- ### Define a Windows RPA Script Source: https://github.com/a943512/pyaibote/blob/main/README.md Inherit from WinBotMain to create a custom automation script. The script_main method serves as the mandatory entry point for execution. ```python # 1. 导入 WinBotMain 类 # 1. Import WinBotMain class from PyAibote import WinBotMain import time,os # 2. 自定义一个脚本类,继承 WinBotMain # 2. Customize a script class and inherit WinBotMain. class CustomWinScript(WinBotMain): # 2.1. 设置是否终端打印输出 DEBUG :输出, INFO :不输出, 默认打印输出 # 2.1. Set whether the terminal prints output DEBUG: output, INFO: no output, and print output by default. Log_Level = "DEBUG" Websocket_Log_Level = "DEBUG" # 2.2. 终端打印信息是否存储LOG文件 True: 储存, False:不存储 # 2.2. Does the terminal print information store the LOG file? True: yes, False: no. Log_Storage = True # 2.3. 注意:script_main 此方法是脚本执行入口必须存在此方法 # 2.3. Note: script_main This method must exist in the script execution portal. def script_main(self): # 查询所有窗口句柄 result = self.find_windows() print(result) # 主函数死循环时win驱动连接断开异常捕获跳出死循环demo示例代码 # while True: # try: # # 死循环中必须加入aibote函数代码 # result = self.find_windows() # print("我是个死循环") # time.sleep(2) # # 服务端捕获客户端断开异常跳出线程循环结束连接 # except OSError as e: # break # # 捕获其他非连接断开异常 # except Exception as e: # print(e) # 关闭驱动 方法一 终端命令杀死驱动 # self.close_driver_local() # 关闭驱动 方法二 驱动自动断开连接 # self.close_driver() # 关闭驱动 方法三 终端命令杀死驱动 # os.popen('taskkill /f /t /im "WindowsDriver.exe"') # 关闭驱动 方法四 cmd终端直接输入杀死驱动 # taskkill /f /t /im "WindowsDriver.exe" if __name__ == '__main__': # 3. IP为:0.0.0.0, 监听 9999 号端口 # 3. IP: 0.0.0, listening to port 9999. # 3.1. 在远端部署脚本时,请设置 Debug=False,客户端手动启动 WindowsDriver.exe 时需指定远端 IP 或端口号 # 3.1. When deploying the script remotely, please set Debug=False, and the client needs to specify the remote IP or port number when manually starting the WindowsDriver.exe. # 3.2. 命令行启动示例:WindowsDriver.exe "127.0.0.1" 9999 {'Name':'PyAibote'} # 3.2. Command line startup example: "127.0.0.1" 9999 {'Name':'PyAibote'} CustomWinScript.execute(IP="0.0.0.0", Port=9999, Debug=True, Qt=None, WebsocketSwitch=False, WebsocketPort=8888) ``` -------------------------------- ### Implement Digital Human Script Source: https://github.com/a943512/pyaibote/blob/main/README.md Defines a custom class inheriting from HumanBotMain to manage digital human operations, including logging configuration and the mandatory script_main entry point. ```python # 1. 导入 HumanBotMain 类 # 1. Import HumanBotMain class from PyAibote import HumanBotMain import time,os # 2. 自定义一个脚本类,继承 HumanBotMain # 2. Customize a script class and inherit HumanBotMain. class CustomWinScript(HumanBotMain): # 2.1. 设置是否终端打印输出 DEBUG :输出, INFO :不输出, 默认打印输出 # 2.1. Set whether the terminal prints output DEBUG: output, INFO: no output, and print output by default. Log_Level = "DEBUG" Websocket_Log_Level = "DEBUG" # 2.2. 终端打印信息是否存储LOG文件 True: 储存, False:不存储 # 2.2. Does the terminal print information store the LOG file? True: yes, False: no. Log_Storage = True # 2.3. 注意:script_main 此方法是脚本执行入口必须存在此方法 # 2.3. Note: script_main This method must exist in the script execution portal. def script_main(self): # 初始化数字人 self.init_new_metahuman(r"D:\Project\Aibote\2024-4-11\NewHuman\model", 0.5, False, False, "") # 切换数字人形象 self.new_metahuman_switch_action(r"D:\Project\CompanyInformation\PaidItem\DigitalHuman\Static\Img\666.mp4", 0.5, False) # 添加数字人背景 self.new_metahuman_add_background(r"D:\Project\CompanyInformation\PaidItem\DigitalHuman\Static\Backgroun\1.mp4") # 关闭驱动 方法一 # os.popen('taskkill /f /t /im "AiDriver.exe"') # 关闭驱动 方法二 终端直接输入 # taskkill /f /t /im "AiDriver.exe" # 关闭驱动 方法三 驱动端关闭 [适用于多进程开发] # result = self.new_metahuman_close_driver() # 主函数死循环时数字人驱动连接断开异常捕获跳出死循环demo示例代码 # while True: # try: # # 死循环中必须加入aibote函数代码 # result = self.new_metahuman_get_windows_id() # print("我是个死循环") # time.sleep(2) # # 服务端捕获客户端断开异常跳出线程循环结束连接 # except OSError as e: # break # # 捕获其他非连接断开异常 # except Exception as e: # print(e) # 关闭驱动 方法一 # os.popen('taskkill /f /t /im "AiDriver.exe"') # 关闭驱动 方法二 终端直接输入 # taskkill /f /t /im "AiDriver.exe" # 关闭驱动 方法三 驱动端关闭 [适用于多进程开发] # result = self.new_metahuman_close_driver() if __name__ == '__main__': # 3. IP为:0.0.0.0, 监听 9999 号端口 # 3. IP: 0.0.0, listening to port 9999. # 3.1. 在远端部署脚本时,请设置 Debug=False,客户端手动启动 WindowsDriver.exe 时需指定远端 IP 或端口号 # 3.1. When deploying the script remotely, please set Debug=False, and the client needs to specify the remote IP or port number when manually starting the WindowsDriver.exe. # 3.2. 命令行启动示例:AiDriver.exe "127.0.0.1" 9999 {'Name':'PyAibote'} # 3.2. Command line startup example: AiDriver.exe "127.0.0.1" 9999 {'Name':'PyAibote'} # 3.3 Qt 使用线程启动时传递的Qt对象用来和Qt UI窗口通信 # 3.3 Qt Use the Qt object passed when the Qt thread starts to communicate with the Qt UI window CustomWinScript.execute("0.0.0.0", 9999, Debug=True, Qt = None, WebsocketSwitch=False, WebsocketPort=8888) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.