当前位置:   article > 正文

python 百度翻译_##y6sobwx21##page

##y6sobwx21##page
import json
import requests

def fangYi(data1):
    url = "https://fanyi.baidu.com/sug"
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0 Win64 x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"
    }
    data = {"kw": data1}
    r = requests.post(url=url, headers=headers,
                      data=data).content.decode()
    j = json.loads(r)
    if j['errno'] == 0:
        try:
            v = j['data'][0]['v']
            print(v + "\n")
        except:
            print('falied,try again!!!\n')


if __name__ == '__main__':
    while True:
        data1 = input("press q quit:\n")
        if data1 == "q":
            break
        else:
            fangYi(data1)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/156428?site
推荐阅读
相关标签
  

闽ICP备14008679号