比特浏览器自动流程训练

1.所需环境requests 库,json ,python3.5或者更高

pip install requests

json: 用于解析和生成 JSON 数据。这是 Python 标准库的一部分,无需额外安装

输出已经完成安装的信息就好。

2.根据官方的接口攥写相关py代码

官方地址
浏览器接口 - 比特指纹浏览器 (bitbrowser.cn)

代码示例:排列

import requests
import json
import time
import sys

def get_open_windows(ids):
    url = "http://127.0.0.1:54345/browser/pids"  # 替换为实际的 URL
    headers = {'Content-Type': 'application/json'}

    data = {
        "ids": ids  # 窗口id集合
    }

    response = requests.post(url, data=json.dumps(data), headers=headers)

    if response.status_code == 200 and response.json()["success"]:
        return response.json()["data"]
    else:
        print("Error:", response.status_code, response.text)
        sys.exit()  # 如果响应状态码不是 200 或 success 为 false,停止脚本

def arrange_windows():
    url = "http://127.0.0.1:54345/windowbounds"  # 替换为实际的 URL
    headers = {'Content-Type': 'application/json'}

    data = {
        "type": "box",
        "startX": 0,
        "startY": 0,
        "width": 683,
        "height": 800,
        "col": 5,
        "spaceX": 0,
        "spaceY": 0,
        "offsetX": 0,
        "offsetY": 0,
        
    }

    response = requests.post(url, data=json.dumps(data), headers=headers)

    if response.status_code == 200:
        print("Success:", response.json())
    else:
        print("Error:", response.status_code, response.text)

# 主程序开始
if __name__ == '__main__':
    while True:
        window_ids = ["02d39dd4f9c54e40bc1ef51929d27235", "39dd4f4e40bc1ef51929d27232sdf3ds"]  # 替换为实际的窗口 ID
        open_windows = get_open_windows(window_ids)
        if open_windows:
            arrange_windows()
        time.sleep(60)

3.利用bat批处理一键运行脚本

@echo off
PowerShell -Command "& {cd E:\bit_rpa\python-demo; python arrange_windows.py}"
pause

文章作者: 轻语清风
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 达达的博客
精选教程 教程
喜欢就支持一下吧