使用 requests.post 方法抓取有道翻译结果

import requests as rq
import json


def get_translate(word=None):
    url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
    From_date = {'i': word, 'from': 'AUTO',
                 'to': 'AUTO',
                 'smartresult': 'dict',
                 'client': 'fanyideskweb',
                 'salt': '15729146641042',
                 'sign': 'f4fb47a412b188adc5e2094f5faa7e7a',
                 'ts': '1572914664104',
                 'bv': '6280b872caa9d459d8fdf731861eaa34',
                 'doctype': 'json',
                 'version': '2.1',
                 'keyfrom': 'fanyi.web',
                 'action': 'FY_BY_CLICKBUTTION'}
    response = rq.post(url, data=From_date)
    txt = json.loads(response.text)
    print(txt['translateResult'][0][0]['tgt'])


if __name__ == '__main__':
    word = input()
    get_translate(word)

注意URL需要把地址后面的_o去掉 不然会返回50!

posted @ 2019-11-05 09:15  WAKBGAN  阅读(468)  评论(0编辑  收藏  举报