zoukankan      html  css  js  c++  java
  • 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()
    

      

  • 相关阅读:
    TeX中的引号
    竖式问题
    蛇形填数
    开灯问题
    排列
    分数化小数
    子序列的和
    cookie
    post请求
    get请求
  • 原文地址:https://www.cnblogs.com/royfans/p/7417914.html
Copyright © 2011-2022 走看看