这里记录一些在根据视频/网站学习爬虫时,遇到的一些问题。一般是由于视频/网站时间较早,相关代码语法网站等需要修改。这里做一些简单记录,当然,可能过了半载一年,又失效了。
一、有道翻译
解决:有道翻译 ‘errorCode’: 50
根据有道翻译的结果页信息,获取到的url为:http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule
使用这个地址,是无法爬虫成功的,会报错。需要进行修改之后,才会返回正常结果。
修改如下(去掉translate_o中的_o):
tobe_translate = input('Please input your word:')
# tobe_translate = '你好' #开发时避免每次输入耽误时间
data = {
'i': tobe_translate,
'from': 'AUTO',
'to': 'AUTO',
'smartresult': 'dict',
'client': 'fanyideskweb',
'salt': '15534990752679',
'sign': '8068ceaab29dca41031a3695a052208a',
'ts': '1553499075267',
'bv': '22c4e55facde8e7a20b16e256e9fdfa1',
'doctype': 'json',
'version': '2.1',
'keyfrom': 'fanyi.web',
'action': 'FY_BY_REALTlME',
'typoResult': 'false'}
# data转换成request需要的数据类型
data = urllib.parse.urlencode(data).encode('utf-8')
# 发送请求
youdaofanyi = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
整体源代码获取地址 https://github.com/shixin398/Python3