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();
- 如何closuresnode.js中的数据库连接?
- 从一个ID数组到一个名称数组(mongo,nodejs)
- Node.js:我如何将全局variables传递给通过require()插入的文件?
- 从expres传递数组到jade客户端的javascript
- JavaScript不能从networking驱动器工作
- 如何将html呈现到页面中,而不是将整个视图呈现为Node.js + express应用程序?
- CommonJS模块没有设置variables的值?
- 你将如何将函数构造函数对象方法与原型一起封装在使用exports或module.exports的单个模块中
- 为什么Mongoose用_idreplace对象中的键/值对?