python 用得好,每日下班早

import httpx, json, openpyxl, time
deeplx_api = “http://127.0.0.1:1188/translate”
wb = openpyxl.load_workbook(“c2023.xlsx”)
sheet = wb[“Sheet1”]
for i in range(sheet.max_row):
    row_line = str(i + 1)
    time.sleep(2)
    data = {
        “text”: sheet[“A” + row_line].value,
        “source_lang”: “ZH”,
        “target_lang”: “EN”,
    }
    post_data = json.dumps(data)
    r = httpx.post(url=deeplx_api, data=post_data).text
    data = json.loads(r)
    name = data[“data”]
    print(“data: “, name)
    sheet[“B” + row_line] = name
    print(i)
wb.save(“translated.xlsx”)
欢迎访问本网站!
雨木霜月 » python 用得好,每日下班早

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据