golang执行js代码时遇到了window对象,我用atto库执行会报错,要怎么解决?

gsliyanbing · 2017-10-18 13:50:03 · 2342 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2017-10-18 13:50:03 的主题,其中的信息可能已经有所发展或是发生改变。

atto库貌似没法儿模拟浏览器对象,在js中遇到window时就会报错!有遇到过的大神帮帮忙该怎么解决非常感谢


有疑问加站长微信联系(非本文作者)

第 1 条附言  ·  2017-10-19 02:20:09

因为在做一个 Golang 的爬虫项目,遇到一个用js实现的类似于加密算法,不太好分析!想直接用第三方库(github.com/robertkrimen/otto)执行这个js,但是报错,因为otto不支持浏览器window对象!附上部分代码截图!有遇到过的大神帮帮忙,非常感谢整体js折叠.jpgJS结尾.jpg运行代码.jpg

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2342 次点击  
加入收藏 微博
7 回复  |  直到 2020-08-13 14:26:56
channel
channel · #1 · 7年之前

这个库地址是?

gsliyanbing
gsliyanbing · #2 · 7年之前

使用的是这个库 github.com/robertkrimen/otto

附上部分代码截图

gsliyanbing
gsliyanbing · #3 · 7年之前

WechatIMG27.jpgWechatIMG26.jpgWechatIMG25.jpg

gsliyanbing
gsliyanbing · #4 · 7年之前
channelchannel #1 回复

这个库地址是?

github.com/robertkrimen/otto

channel
channel · #5 · 7年之前

Where is setTimeout/setInterval?

These timing functions are not actually part of the ECMA-262 specification. Typically, they belong to the window object (in the browser). It would not be difficult to provide something like these via Go, but you probably want to wrap otto in an event loop in that case.

可见,window 是浏览器实现的对象,并非标准 js 的,所以没法使用它。

PS:otto 库,你在问题中写成了 atto 库,太粗心大意了吧!

gsliyanbing
gsliyanbing · #6 · 7年之前
channelchannel #5 回复

> Where is setTimeout/setInterval? > >These timing functions are not actually part of the ECMA-262 specification. Typically, they belong to the `window` object (in the browser). It would not be difficult to provide something like these via Go, but you probably want to wrap otto in an event loop in that case. 可见,window 是浏览器实现的对象,并非标准 js 的,所以没法使用它。 PS:`otto` 库,你在问题中写成了 `atto` 库,太粗心大意了吧!

不小心写错了,因为这个js里面东西太多了,不太好分析!

MUMUCHENGMIAN
MUMUCHENGMIAN · #7 · 5年之前

您好,请问您解决这个问题了吗?

添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传