zoukankan      html  css  js  c++  java
  • google 翻译

    url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=";
    long start = System.currentTimeMillis();
    Map<String, String> header = new HashMap<>();
    header.put("User-Agent",
    		"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31");
    
    JSONArray jsonArray = httpUtil.get(googleTranslateUrl + "香港", header);
    log.info("*****************jsonArray is {}", jsonArray);
    JSONArray retStr = jsonArray.getJSONArray(0).getJSONArray(0).getJSONArray(0);
    log.info("***retStr is {}", retStr);
    String cityName = retStr.getString(0);
    log.info("***cityName is {}", cityName);
    log.info("cost time is {}",(System.currentTimeMillis()-start));
    

    请求后的json 结果:

    [
        [
            [
                "Hong Kong",
                "香港",
                null,
                null,
                2
            ]
        ],
        null,
        "zh-CN",
        null,
        null,
        null,
        null,
        null,
        [
            [
                "zh-CN"
            ],
            null,
            [
                0.9609375
            ],
            [
                "zh-CN"
            ]
        ]
    ]
    

    一段时间内大量请求的话就需要使用代理来发送请求,避免被和谐(反爬虫机制)

  • 相关阅读:
    linux 环境下安装oracle11g方法及安装过程中遇上的问题解决方法
    Opencv Mat的操作
    Opencv 的数据结构
    Opencv 摄像头矫正
    LM算法
    Python 正则表达式
    find grep
    Socket 入门
    Python thread
    Javascript实现页面跳转的几种方式
  • 原文地址:https://www.cnblogs.com/wanthune/p/11410702.html
Copyright © 2011-2022 走看看