zoukankan      html  css  js  c++  java
  • 有道字典爬虫

    有道字典翻译接口:

    from urllib import request
    from urllib import response
    from urllib import parse
    
    key = input("请输入要翻译的文字:")
    formdata = {
        "action":"FY_BY_REALTIME",
        "client":"fanyideskweb",
        "doctype":"json",
        "from":"AUTO",
        "i":key,
        "keyfrom":"fanyi.web",
        "smartresult":"dict",
        "to": "AUTO",
        "typoResult": "false",
        "version": "2.1"
    }
    
    headers = {
                  "Origin": "http://fanyi.youdao.com",
                  "Connection": "Keep-Alive",
                  "X-Requested-With": "XMLHttpRequest",
                  "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36",
                  "Accept":"application / json, text / javascript, * / *; q = 0.01",
                  "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
                  "Accept-Language": "zh-CN,zh;q=0.9",
                  "Cookie": "OUTFOX_SEARCH_USER_ID=-1422077745@10.168.8.63; JSESSIONID=aaa3ISYIWd-tGeQO-Kjzw; OUTFOX_SEARCH_USER_ID_NCOO=1045054394.1731315; DICT_UGC=be3af0da19b5c5e6aa4e17bd8d90b28a|; JSESSIONID=abcxAFXVMlyT2gJevVjzw; ___rl__test__cookies=1538880352137"
    
    }
    data = bytes(parse.urlencode(formdata),"utf-8")
    url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"
    req = request.Request(url,data=data,headers=headers)
    res = request.urlopen(req)
    print(res.read().decode("utf-8"))
  • 相关阅读:
    day 3 python 函数 -- lambda -- 内置函数 -- 进制转换
    day 2 基本类型和函数
    linux 的常用命令
    python & diretory 对象
    python & list对象
    python & str对象函数
    python全栈之路 1 python的基本介绍
    centos6.5 配置SSH
    js禁止高频率连续点击思路
    $.ajax参数备注-转转转
  • 原文地址:https://www.cnblogs.com/lxk2010012997/p/9749600.html
Copyright © 2011-2022 走看看