1、Python request(爬蟲-百度翻譯)


#encoding=utf-8

import requests
def fanyi():
    while True:
        context = input("請輸入翻譯的內容(退出q):")

        if context in ['q','Q']:
            break
        else:
            url = 'http://fanyi.baidu.com/v2transapi/'
            data = {
                'from':'en',
                'to':'zh',
                'query':context,
                'transtype':'translang',
                'simple_means_flag':'3',
            }
            headers ={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0'}
            response = requests.post(url,data,headers=headers)
            head = response.headers

            # text = response.text
            # text = json.loads(text)
            # res = text['trans_result']['data'][0]['dst']
            # print(res)
            print(head['Content-Type'])
            print(response.json()['trans_result']['data'][0]['dst'])

fanyi()

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM