import requests
import json
from urllib.parse import quote
import base64
from PIL import Image
import io

# API 端点 URL（请替换为实际接口地址）
# api_url = "http://116.63.110.220:19801/screenshot"
api_url = "http://localhost:19801/screenshot"

# 请求参数
url = "https://www.icourse163.org/course/WUST-1206144803?from=searchPage&outVendor=zw_mooc_pcssjg_"
url = "https://www.baidu.com/"
params = {
    "url": url,   #   需要截图的目标 URL，
    "width": 1290,  # 指定宽度
    "height": 700  # 指定高度
}
params = json.dumps(params, ensure_ascii=False)

try:
    # 发送 GET 请求
    response = requests.post(api_url, data=params)

    # 检查响应状态码
    if response.status_code == 200:
        data = response.json()

        obs_url = data['obs_url']
        print("目标网站截屏保存地址：", obs_url)

    else:
        print("error")


except Exception as e:
    print(f"发生异常: {str(e)}")