Tag: 噩梦

问题与NPM需要

我运行一个Nightmare.js脚本,并在其中我试图require lodash(本地安装npm,在node_modules中,在package.json中注册)。 index.js: var Nightmare = require('nightmare'); var _ = require('lodash'); function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max – min)) + min; } function getElms(elm) { var elsm = document.querySelectorAll(elm); return _.map(elsm, function(elem){ return elem.innerHTML; }); } var someWebsite = new Nightmare({ show: false }) .goto( ***some url*** […]

当使用Nightmare.js或phantom.js来抓取网站时,为什么会显示幻像出现错误

我试图用phantom.js编写一个web-spider。 但是,我收到了很多错误信息,我不知道为什么。 我的代码如下所示: 使用Nightmare.js : var Nightmare = require('nightmare'); new Nightmare() .goto('http://www.amazon.com/Aroma-Housewares-ASP-137-3-Quart-Super/dp/B00024JQ3Q') .evaluate( function(){ return document.getElementById('priceblock_ourprice').textContent; }, function( numAnchors ){ console.log(numAnchors); }) .run(); 使用phantom.js : var page = require('webpage').create(); console.log('The default user agent is ' + page.settings.userAgent); page.open('http://www.amazon.com/Aroma-Housewares-ASP-137-3-Quart-Super/dp/B00024JQ3Q', function(status) { if (status !== 'success') { console.log('Unable to access network'); } else { var ua = […]

梦魇在while循环中运行函数que(让循环等到que完成)

我试图在一个while循环中运行噩梦。 我的问题是while循环不等待噩梦完成。 这是我的示例代码: var Nightmare = require('nightmare'); var Screenshot = require('nightmare-screenshot'); var i = 0; while(i < 10) { var nightmare = new Nightmare(); nightmare.goto('https:/website/?id='+ i); nightmare.screenshot('/home/linaro/cointellect_bot/screenshot1.png'); nightmare.use(Screenshot.screenshotSelector('screenshot' + i + '.png', 'img[id="test"]')); nightmare.run(); } 是否有可能让循环等到噩梦完成它的function队列? 我还有什么其他的select?

nightmare.js如何实现像window.callPhantom()函数的function?

我有以下代码: var nightmare = Nightmare(option) nightmare .goto('some url') .evaluate(() => { window.callback = function(cid) { // do some stuff // should screenshot at this point. } }) .screenshot('./png.png') //Doesn't get accurate png here .end() 我想要的是在浏览器作用域中添加一个callback函数,而在浏览器作用域中,如果在某个点上存在,我会调用callback函数。 在那个callback函数中,我会调用主进程在那个callback函数的末尾截图。 它像phantom.js中的window.callPhantom 。 但是我无法在nightmare.js中find这个方法。 有任何想法吗?

如何使用promise和vo.js返回Hapi答复

我有一个asynchronous的nightmare.js过程,它使用vo.jsstream程控制和一个生成器: vo(function *(url) { return yield request.get(url); })('http://lapwinglabs.com', function(err, res) { // … }) 这需要使用reply()接口返回对Hapi(v.13.0.0)的承诺。 我已经看到Bluebird和其他承诺库的例子,例如: 如何从hapi.js路由处理程序之外进行回复 ,但是无法适应vo.js. 有人可以提供一个这样的例子吗? server.js server.route({ method: 'GET', path:'/overview', handler: function (request, reply) { let crawl = scrape.doCrawl({"user": USERNAME, "pass": PASSWORD}); reply( … ).code( 200 ); } }); scrape.js module.exports = { DoCrawl: function(credentials) { var Nightmare = require('nightmare'); var […]

NightmareJS没有closures浏览器

我已经习惯了PhantomJS和Watir,它们都提供了一个开箱即用的REPL。 REPL允许我在当前运行的浏览器上执行自动调用。 这是制作自动化脚本的有趣方式,因为我可以在构build自动化脚本时观察每个步骤的效果。 实际上,我甚至可以编写一个脚本来定义打开浏览器,执行login和其他常见任务的方法,然后在通用Node或Ruby REPL中按需要调用它们。 我可以在不closures浏览器(Electron)的情况下执行NightmareJS调用吗?

如何设置Nightmare.js中的电子大小?

“ 恶梦”文档不指定如何设置浏览器的详细信息。 我猜这是这样的,但它不起作用。 有任何想法吗? const nightmare = new Nightmare({'show': show, 'BrowserWindow': {height: 900}});

从Nightmare.js返回HTML正文

我目前正在做一些与cheerio和nightmare刮。 我之所以用这两种而不仅仅是cheerio是因为我必须操纵这个网站才能find我想要的部分,而且我发现这些剧本的噩梦非常好。 所以,现在我正在使用nightmare ,直到我需要的信息显示部分。 之后,在evaluate()我试图以某种方式返回当前的html ,然后传递给cheerio做刮。 问题是我不知道如何从document对象中检索html。 文件中是否有属性返回完整的主体? 这是我想要做的: var Nightmare = require('nightmare'); var nightmare = Nightmare({show:true}) var express = require('express'); var fs = require('fs'); var request = require('request'); var cheerio = require('cheerio'); var app = express(); var urlWeb = "url"; var selectCity = "#ddl_city" nightmare .goto(urlWeb) .wait(selectCity) .select('#ddl_city', '19') .wait(6000) .select('#ddl_theater', '12') .wait(1000) .click('#btn_enter') […]

使用PhantomJS处理多个用户请求到多个远程Web表单

我使用NightmareJS创build了一个ExpressJS应用程序,它有一个表单,当我们填写表单并提交时,它将请求发送给一些远程表单并计算数据并返回这些结果。 但问题是只有当单个客户提交表单时才有效。 当多个客户同时提交表单时,它不起作用。 这可能是什么原因以及如何解决这个问题? 前端JS脚本 $(document).ready(function () { $("#calculate-form").submit(function (event) { var request; if (request) { request.abort(); } var $form = $(this); var $inputs = $form.find("input, select, button, textarea"); var serializedData = $form.serialize(); $inputs.prop("disabled", true); form1(request, serializedData, $inputs, '/example1', '#form1'); function form1(request, serializedData, inputs, appUrl, displayElement) { request = $.ajax({ url: appUrl, type: "post", data: […]

Nightmarejs在同一testing中的多个页面

我试图从Drupal站点上的两个网页中拉出标题标签文本。 我想用Nightmarejs。 这是我的代码到目前为止: // get the <title> text from inside the Drupal site var Nightmare = require('nightmare'); var user = 'foobar@example.com'; var pass = 'foobar'; new Nightmare() .goto('http://example.com/user') .type('#edit-name', user) .type('#edit-pass', pass) .click('.searchsubmit') .wait() .evaluate(function () { return document.getElementsByTagName("TITLE")[0]; }, function (res) { console.log('Homepage title: '+res.text); }) .run(function(err, nightmare){ console.log('Done1.'); // step 2 nightmare .goto('http://example.com/admin') […]