鱼C论坛

 找回密码
 立即注册
查看: 1185|回复: 8

[已解决]关于爬虫的小问题

[复制链接]
发表于 2018-2-11 10:57:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 Qking 于 2018-2-11 11:20 编辑

先上代码,注释掉的部分是实在没办法,按小甲鱼老师的书上源代码打的试了一下,而且参数里面为什么没有'ue','type','xmlVersion'

  1. import urllib.request as re
  2. import urllib.parse as par
  3. import json

  4. content = input("请输入需要翻译的内容:")
  5. url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
  6. #url = "http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=http://www.youdao.com/"
  7. data = {}
  8. head = {}
  9. head['Referer'] = 'http://fanyi.youdao.com/'
  10. head['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0'
  11. data['from'] = 'AUTO'
  12. data['doctype'] = 'json'
  13. #data['type'] = 'AUTO'
  14. #data['xmlVersion'] = '1.6'
  15. #data['ue'] = 'UTF-8'
  16. data['version'] = '2.1'
  17. data['key.from'] = 'fanyi.web'
  18. data['typoResult'] = 'false'
  19. #data['typoResult'] = 'true'
  20. data['to'] = 'AUTO'
  21. data['i'] = content
  22. data = par.urlencode(data).encode('utf - 8')

  23. req = re.Request(url,data,head)
  24. response = re.urlopen(req)
  25. html = response.read().decode('utf - 8')
  26. target = json.loads(html)
  27. print("翻译的结果:%s"%(target['translateResult'][0][0]['tgt']))
复制代码

最佳答案
2018-2-11 11:08:31
  1. url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
复制代码

把里面的 '_o' 去掉。
1.png
2.png
3.png
6.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-2-11 11:07:35 | 显示全部楼层
  1. def translator(txt):
  2.     import json
  3.     import urllib.request

  4.     url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&sessionFrom=https://www.baidu.com/link'
  5.     data = {'from': 'AUTO', 'to': 'AUTO', 'smartresult': 'dict', 'client': 'fanyideskweb', 'salt': '1500092479607',
  6.             'sign': 'c98235a85b213d482b8e65f6b1065e26', 'doctype': 'json', 'version': '2.1', 'keyfrom': 'fanyi.web',
  7.             'action': 'FY_BY_CL1CKBUTTON', 'typoResult': 'true', 'i': txt}

  8.     data = urllib.parse.urlencode(data).encode('utf-8')
  9.     wy = urllib.request.urlopen(url, data)
  10.     html = wy.read().decode('utf-8')
  11.     ta = json.loads(html)
  12.     return ta['translateResult'][0][0]['tgt']
复制代码

有道也很难啊,小甲鱼老师带起了一波人爬它,所以他改了,这个应该能用。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2018-2-11 11:08:31 | 显示全部楼层    本楼为最佳答案   
  1. url = 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
复制代码

把里面的 '_o' 去掉。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 1

使用道具 举报

 楼主| 发表于 2018-2-11 11:24:44 | 显示全部楼层
°蓝鲤歌蓝 发表于 2018-2-11 11:08
把里面的 '_o' 去掉。

。。。为什么  居然真的可以了。。。可是请求网址里面有'_o'啊...
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-2-11 11:26:58 | 显示全部楼层
Qking 发表于 2018-2-11 11:24
。。。为什么  居然真的可以了。。。可是请求网址里面有'_o'啊...

不好意思,原因一直没找到,我觉得是有道的加密措施。
楼上大佬的代码也是网址里面没有 '_o' 才能爬取。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-2-11 11:30:28 | 显示全部楼层
新手·ing 发表于 2018-2-11 11:07
有道也很难啊,小甲鱼老师带起了一波人爬它,所以他改了,这个应该能用。

大佬  你知道为什么去掉url里面的'_o'就可以了吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-2-11 11:32:32 | 显示全部楼层
Qking 发表于 2018-2-11 11:30
大佬  你知道为什么去掉url里面的'_o'就可以了吗?

不给我最佳。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-2-11 11:33:15 | 显示全部楼层
Qking 发表于 2018-2-11 11:30
大佬  你知道为什么去掉url里面的'_o'就可以了吗?

这个。。。
就是上面那个大佬的解释,有道的加密,后来被破解了,解法就是去掉_o。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-2-11 11:33:45 | 显示全部楼层
Qking 发表于 2018-2-11 11:30
大佬  你知道为什么去掉url里面的'_o'就可以了吗?

这个。。
就是上面那个大佬的解释,加密了。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-18 17:51

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表