covwsf 发表于 2020-6-29 18:57:49

救救孩子 新写的爬虫到底哪错了啊

"""
Created on Mon Jun 29 15:25:26 2020

@author: Corvus
"""

import requests
from hashlib import md5
import time
import random

   

def fasong(x):
    url="http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule"

    headers={
      'Accept': 'pplication/json, text/javascript, */*; q=0.01',
      'Accept-Encoding': 'gzip, deflate',
      'Accept-Language': 'zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7',
      'Connection': 'keep-alive',
      'Content-Length': '239',
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
      'Cookie': 'OUTFOX_SEARCH_USER_ID=1879194388@10.169.0.102; OUTFOX_SEARCH_USER_ID_NCOO=1407266575.6763363; JSESSIONID=aaa09S_4yRwnccJhNw-lx; ___rl__test__cookies=1593422023525',
      'Host': 'fanyi.youdao.com',
      'Origin': 'http://fanyi.youdao.com',
      'Referer': 'http://fanyi.youdao.com/',
      'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
      'X-Requested-With': 'XMLHttpRequest',
      }
   
    r = str(int(time.time()*1000))
    i = r + str(random.randint(0, 9))
    s = md5()
    sign = "fanyideskweb" + x + i + "mmbP%A-r6U3Nw(n]BjuEU"
    s.update(sign.encode())
    sign = s.hexdigest()
    print(x,'\n','\n',r,'\n',i,'\n',s.hexdigest(),'\n')
   
    words={
      'i': x,
      'from': 'AUTO',
      'to': 'AUTO',
      'smartresult':' dict',
      'client': 'fanyideskweb',
      'salt': i,
      'sign': s,
      'ts': r,
      'bv': '02a6ad4308a3443b3732d855273259bf',
      'doctype': 'json',
      'version': '2.1',
      'keyfrom': 'fanyi.web',
      'action': 'FY_BY_CLICKBUTTION',
      }
    result = requests.post(url, data=words, headers=headers)
    print(result)
    print(result.text)
   
if __name__ == '__main__':
    fasong(input('需要翻译的词:'))
   


结果:
Python 3.7.6 (default, Jan8 2020, 20:23:39)
Type "copyright", "credits" or "license" for more information.

IPython 7.12.0 -- An enhanced Interactive Python.

runfile('D:/pyth/未命名0.py', wdir='D:/pyth')

需要翻译的词:go
go

1593428123294
15934281232945
f1a893db098ad88abc887481a068957e

<Response >
{"errorCode":50}


对照了半天也不知道错哪了

Twilight6 发表于 2020-6-29 20:07:26

把 链接里的 _o 去掉 :

http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule

陈尚涵 发表于 2020-7-7 12:33:07

额,看不懂
页: [1]
查看完整版本: 救救孩子 新写的爬虫到底哪错了啊