node.js上的node-phantom模块的问题
var phantom = require('node-phantom'); var fs = require('fs'); var express = require('express'); var app = express(); app.get('/download', function(req, res) { res.write("<h1>helloworld</h1>"); phantom.create(function(err,ph) { alert(err) return ph.createPage(function(err,page) { alert(err) return page.open("http://tilomitra.com/repository/screenscrape/ajax.html", function(err,status) { console.log("opened site? ", status); page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', function(err) { //jQuery Loaded. //Wait for a bit for AJAX content to load on the page. Here, we are waiting 5 seconds. setTimeout(function() { return page.evaluate(function() { //Get what you want from the page using jQuery. A good way is to populate an object with all the jQuery commands that you need and then return the object. var h2Arr = [], pArr = []; $('h2').each(function() { h2Arr.push($(this).html()); }); $('p').each(function() { pArr.push($(this).html()); }); return { h2: h2Arr, p: pArr }; }, function(err,result) { console.log(result); ph.exit(); }); }, 5000); }); }); }); }); }); var server = app.listen(3040, function() { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
运行node.js后,出现下面两条信息:
phantom stdout: TypeError: undefined is not an object (evaluating 'phantom.args[0]')
phantom stdout: phantomjs://code/bridge.js:3 in global code求解决!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
phantom=require('phantom'),