Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 1.08 KB

578-192645-有道翻译接口.sy.md

File metadata and controls

45 lines (33 loc) · 1.08 KB
show version enable_checker
step
1.0
true

语法 html 遍历

回忆

import requests

def ch_en(txt):
    url = f'https://dict.youdao.com/suggest?num=5&ver=3.0&doctype=json&cache=false&le=en&q={txt}'

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 SLBrowser/9.0.0.10191 SLBChan/51'
    }

    resq = requests.get(url, headers=headers)

    dic = resq.json()
    res = dic["data"]["entries"][0]["explain"]
    return res

def ch_de(txt):
    url = f'https://dict.youdao.com/suggest?num=5&ver=3.0&doctype=json&cache=false&le=de&q={txt}'

    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 SLBrowser/9.0.0.10191 SLBChan/51'
    }

    resq = requests.get(url, headers=headers)

    dic = resq.json()
    res = dic["data"]["entries"][0]["explain"].split(";")
    return res[1].strip()

content = "衣服"
en_res = ch_en(content)
de_res = ch_de(content)
print(en_res)
print(de_res)