鱼C论坛

 找回密码
 立即注册
查看: 991|回复: 2

爬虫有道词典

[复制链接]
发表于 2018-6-6 15:58:19 | 显示全部楼层 |阅读模式

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

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

x
  1. import urllib.request
  2. import urllib.parse
  3. import json


  4. content = input("qing  shu  ru:")
  5. url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc'

  6. head = {}
  7. head['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0'

  8. data = {
  9.         "type" : "AUTO",
  10.         "i" : content,
  11.         "doctype" : "json",
  12.         "xmlVersion" : "1.8",
  13.         "keyfrom" : "fanyi.web",
  14.         "ue" : "UTF-8",
  15.         "action" : "FY_BY_CLICKBUTTON",
  16.         "typoResult" : "true"
  17.     }
  18. data = urllib.parse.urlencode(data).encode('utf-8')

  19. req = urllib.request.Request(url,data,head)
  20. response = urllib.request.urlopen(req)
  21. html = response.read().decode('utf-8')

  22. target = json.loads(html)
  23. target = target['translateResult'][0][0]['tgt']

  24. print(target)
复制代码

为什么会请求来源非法  ,我用鱼C源程序也是这样  一开始以为自己打错或打差  求大神指点一二  万分感谢!
捕获.PNG
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-6-6 17:41:31 | 显示全部楼层
源代码都是以前的了。现在人家网站改版反爬了,也就是说要想爬那么你要有相当的技术才行。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2018-6-10 14:28:16 | 显示全部楼层
原来这样呀 谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-12-30 16:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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