Nodejs从post请求接收和修改html文件回调

时间:2013-07-26 09:15:22

标签: node.js

我对nodejs很新,并且我很难尝试提出完全清除以下内容的解决方案:

  1. 制作表格发布请求< - working
  2. 数据以html< - working
  3. 的形式返回
  4. 将data / html和createWriteStream'stdout'带到一个文件或将其保存到DB(我在想redis,因为我只需要在重新运行代码之前将数据TTL设置为15分钟。< - 我将数据保存到高清,虽然我觉得这很笨拙。
  5. 一旦我有data / html文件,我需要使用JS HTML DOM方法来抽取特定的表格单元格数据并发送到http服务器以供客户端查看。 < - 这是我无法工作的部分。
  6. 这是我的代码的链接: https://gist.github.com/bingeboy/6087474

1 个答案:

答案 0 :(得分:0)

我错过了jsdom.jsdom方法。

var jsdom = require("jsdom");

需要:

var jsdom = require("jsdom").jsdom;

这允许窗口回调加载文件。以前我在错误cb中获取该文件。     var fs = require('fs')       ,jsdom = require('jsdom')。jsdom;

var htmlSource = fs.readFileSync(__dirname + "/date.html", "utf8")
  , document = jsdom(htmlSource)
  , window = document.parentWindow;

console.log(typeof window.document.getElementsByClassName); //function
console.log(window.document.getElementsByTagName('a')[1].innerHTML); //logs link text "311.json"