Javascript Node.js 定义文档对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12142709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node.js define document object
提问by Evan
Hi i am trying to run a js function on server side using node.js but there is a problem. The function is using document dom to access some hidden values on the returned html and the document is undefined on node.js, is there a way to define the document object?
嗨,我正在尝试使用 node.js 在服务器端运行一个 js 函数,但有一个问题。该函数使用文档 dom 访问返回的 html 上的一些隐藏值,并且文档在 node.js 上未定义,有没有办法定义文档对象?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
<title></title>
</head>
<body>
<form id="sbb_KoNkmwM" method="post" style="display:none" name="sbb_KoNkmwM">
<input name='sbb_BQGUL' type='checkbox' value='IbNlk' /><input name='sbb_BQGUL' type=
'checkbox' value='huTi' /><input name='sbb_BQGUL' type='checkbox' checked="checked"
value='qGx' /><input name='sbb_BQGUL' type='checkbox' value='WGrkKwxP' /><input name=
'sbb_BQGUL' type='checkbox' value='tgQHP' /><input name='sbb_BQGUL' type='checkbox'
value='dDrn' />
</form>
function sbb_kVnTj() {
var data = 'ZmdiRlhjdQ==';
var rEda = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
ac = 0,
dec = "",
tmp_arr = [];
do {
h1 = rEda.indexOf(data.charAt(i++));
h2 = rEda.indexOf(data.charAt(i++));
h3 = rEda.indexOf(data.charAt(i++));
h4 = rEda.indexOf(data.charAt(i++));
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
o1 = bits >> 16 & 0xff;
o2 = bits >> 8 & 0xff;
o3 = bits & 0xff;
if (h3 == 64) {
tmp_arr[ac++] = String.fromCharCode(o1);
} else if (h4 == 64) {
tmp_arr[ac++] = String.fromCharCode(o1, o2);
} else {
tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
}
} while ( i < data . length );
dec = tmp_arr.join('');
return dec.substr(6, 1);
}
function sbb_MHVY() {
function sbb_iSH(objArr) {
var ts = '';
for (i = 0;
....
采纳答案by juandopazo
Yes, there are ways to create documents in Node. For example you can look at jsdom
: https://github.com/tmpvar/jsdom.
是的,有很多方法可以在 Node.js 中创建文档。例如,您可以查看jsdom
:https: //github.com/tmpvar/jsdom。