JS / Node: – 使用node.ioselect一个标签

我是一个初学者,并且使用node.io来完成一个任务来刮掉这个页面的内容
http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm 。

我想将<P>标签下的文本内容作为string保存在一个variables中。

我的代码是这样的:

var nodeio = require('node.io'); var methods = {input:false,run:function(){this.getHtml(' http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm',function (err,$){

//Handle any request / parsing errors if (err) this.exit(err); var content = $('P'); this.emit(content); }); } } 

exports.job = new nodeio.Job({timeout:10},methods);

这是显示错误:没有匹配'P'的元素。 请帮忙..

我得到Error: No elements matching 'P'执行命令时也Error: No elements matching 'P'

 $ ./node_modules/.bin/node.io query http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm P 

根本原因是在该页面没有结束</P>和node.io不支持自动更正这种格式不正确的HTML像现代的网页浏览器。 而在查询<blockquote>时效果很好:

 $ ./node_modules/.bin/node.io query http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm blockquote 

但是,您可以通过使用selenium技术在真实浏览器上parsingHTML文档来实现。

这里的例子可以运行在你的主机上的节点和selenium网格来获得你想要的。 你可以参考我的其他回答问题你如何得到webdriverjs工作? :

 var webdriverjs = require('webdriverjs'); var client = webdriverjs.remote({ host: 'localhost', port: 4444, desiredCapabilities: { browserName: 'safari', // you can change this accordingly version: '7', platform: "MAC" // you can change this accordingly } }); client.init(); client.url('http://www.nycourts.gov/reporter/3dseries/2013/2013_06966.htm') .getText("P",function(err, text) { console.log (text)}).call(function () {}); client.end();