【发布时间】:2015-03-28 05:39:54
【问题描述】:
我已经编写了一些 javascript 来访问页面并从站点返回数据,但是,我想从这个 html 站点中获取特定元素并使用 document.getElementById 之类的函数。我怎样才能在这里使用这种功能?目前,console.log(chunk) 只是吐出整个 html 正文,我希望能够解析它。
var http = require("http");
var options = {
host: 'www.google.com',
port: 80,
path: '/news'
};
http.get(options, function(res) {
res.setEncoding('utf8');
res.on('data', function(chunk){
console.log(chunk);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
【问题讨论】:
-
欢迎来到 Stack Overflow。我们不是代码生产!请向我们展示您的尝试!
-
我试过了。我所能做的就是打印正文,但不确定如何选择特定元素。
-
你已经说过如何:getElementById
标签: javascript html node.js http