pythonleelee 发表于 2022-6-14 16:50:02

求助爬虫教程

import urllib.request
import urllib.parse

url = 'https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
data = {}
data['i'] = 'i love fish c'
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '16551919254276'
data['sign'] = '41f562cd693998cccd9e490e84640f7b'
data['lts'] = '1655191925427'
data['bv'] = 'b0ff5d17f404993192085bf8b1e93587'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_REALTlME'
data = urllib.parse.urlencode(data).encode('utf-8')

response = urllib.request.urlopen(url, data)
html = response.read().decode('utf-8')

print(html)


我的网页有道不显示解码我就默认打上了UTF-8,跑程序显示了{"errorCode":50}怎么办

临时号 发表于 2022-6-14 17:08:06

将链接里的translate_o改成translate
import urllib.request
import urllib.parse

url = 'https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {}
data['i'] = 'i love fish c'
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '16551919254276'
data['sign'] = '41f562cd693998cccd9e490e84640f7b'
data['lts'] = '1655191925427'
data['bv'] = 'b0ff5d17f404993192085bf8b1e93587'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_REALTlME'
data = urllib.parse.urlencode(data).encode('utf-8')

response = urllib.request.urlopen(url, data)
html = response.read().decode('utf-8')

print(html)

临时号 发表于 2022-6-14 17:09:39

将translate_o改为translate
import urllib.request
import urllib.parse

url = 'https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data = {}
data['i'] = 'i love fish c'
data['from'] = 'AUTO'
data['to'] = 'AUTO'
data['smartresult'] = 'dict'
data['client'] = 'fanyideskweb'
data['salt'] = '16551919254276'
data['sign'] = '41f562cd693998cccd9e490e84640f7b'
data['lts'] = '1655191925427'
data['bv'] = 'b0ff5d17f404993192085bf8b1e93587'
data['doctype'] = 'json'
data['version'] = '2.1'
data['keyfrom'] = 'fanyi.web'
data['action'] = 'FY_BY_REALTlME'
data = urllib.parse.urlencode(data).encode('utf-8')

response = urllib.request.urlopen(url, data)
html = response.read().decode('utf-8')

print(html)

pythonleelee 发表于 2022-6-14 17:29:57

临时号 发表于 2022-6-14 17:09
将translate_o改为translate

感谢大佬

临时号 发表于 2022-6-14 17:33:49

pythonleelee 发表于 2022-6-14 17:29
感谢大佬

如果问题解决了,不要忘了设置最佳答案哦

pythonleelee 发表于 2022-6-15 08:39:34

临时号 发表于 2022-6-14 17:33
如果问题解决了,不要忘了设置最佳答案哦

问题解决了,能否讲一下为什么呢,我是直接复制的网址为啥会出问题

临时号 发表于 2022-6-15 12:39:52

pythonleelee 发表于 2022-6-15 08:39
问题解决了,能否讲一下为什么呢,我是直接复制的网址为啥会出问题

这是有道的反爬机制,而我给你的网址是有道的后门网址

pythonleelee 发表于 2022-6-19 07:47:29

临时号 发表于 2022-6-15 12:39
这是有道的反爬机制,而我给你的网址是有道的后门网址

哦哦,强
页: [1]
查看完整版本: 求助爬虫教程