Cron และ nightmare js

ฉันกำลังพยายามเรียกใช้ cron ด้วย nightmare js ในเครื่อง ขออภัย ฉันมีข้อผิดพลาดนี้

Unhandled rejection (<{"message":"navigation error","code":-...>, no stack trace)

ปัญหาที่เกี่ยวข้อง: Nightmare JS ไม่ทำงาน

ฉันสงสัยว่ามันเชื่อมโยงกับความจริงที่ว่าฝันร้ายต้องใช้อินเทอร์เฟซแบบกราฟิกหรือไม่?

ขอบคุณสำหรับความช่วยเหลือของคุณ,

แก้ไข

ใน cron ของฉัน ฉันมีฟังก์ชัน Promise หนึ่งฟังก์ชันซึ่งประกอบด้วย cron ตามด้วยสัญญา

var job = new CronJob('* */10 * * * *', function() {
    crawl()
  }, function () {
    console.log("crawl ended")
  },
  true
);


job.start();

นี่คือลักษณะของฝันร้าย:

var Nightmare = require('nightmare');
var nightmare = Nightmare({
  typeInterval: 300,
  show: true
});

nightmare
  .goto('https://pageThatRequireToLoginThenDiplayJsonAsText.com')
  .type('[name=email]', '')
  .wait(1000)
  .type('[name=email]', 'myemail')
  .wait(1000)
  .type('[name=password]', '')
  .wait(1000)
  .type('[name=password]', 'mypassword')
  .click('[type=submit]')
  .wait(25000)
  .wait(25000)
  .evaluate(function (page, done) {

    document.documentElement
    done()
  })
  .end()
  .then(function (result) {
    // fs.writeFileSync('testOutput.json', JSON.stringify(result));
    console.log(JSON.stringify(result))
  })
  .catch(function (error) {
    console.error('failed:', error);
  });

เมื่อฉันเรียกใช้ฟังก์ชันการรวบรวมข้อมูลโดยไม่มี cron มันใช้งานได้ดีมาก


person Quentin Del    schedule 01.11.2016    source แหล่งที่มา


คำตอบ (2)


เอาล่ะ ฉันไม่แน่ใจว่าฉันถูกต้องหรือไม่เพราะฉันไม่มีประสบการณ์มากเกินไปในเรื่องนี้ และคุณไม่ได้ระบุสิ่งที่คุณกำหนดไว้ใน cron แต่จากการค้นหาอย่างรวดเร็ว ฉันได้ทำสิ่งที่คุณคาดเดาว่าถูกต้อง เมื่อคุณใช้ cron การโทรของคุณทำผ่าน commandline ตอนนี้ Nightmare สร้างขึ้นจากอิเล็กตรอนซึ่งจะขึ้นอยู่กับโครเมียม จากสิ่งที่ฉันเรียนรู้ที่นี่ อิเล็กตรอนอาจมีข้อบกพร่องที่ทำให้เกิดการหมดเวลา ทุกครั้งที่โหลดหน้าเว็บทันทีบนเบราว์เซอร์ Chromium จริง จากสิ่งที่ฉันรวบรวมมาจนถึงตอนนี้ แอปของคุณต้องการให้อิเล็กตรอนที่สื่อสารกับ Chromium เพื่อให้ทำงานได้อย่างถูกต้อง ซึ่งในกรณีของคุณดูเหมือนว่าจะไม่ทำงาน ฉันขอโทษที่คลุมเครือและอาจผิด แต่สิ่งที่ดีที่สุดที่ฉันสามารถทำได้คือมีข้อมูลเพียงเล็กน้อย

person Ayaskant Mishra    schedule 01.11.2016
comment
ดีสำหรับคุณที่พยายามช่วยแก้ไขปัญหาที่คลุมเครือเช่นนี้ +1 - person Mulan; 01.11.2016
comment
ขอบคุณสำหรับความช่วยเหลือของคุณ Ayaskant ฉันจะพยายามทำงานกับ PhantomJS - person Quentin Del; 01.11.2016
comment
@QuentinDel ฝันร้ายนั้นเหนือกว่าอย่างมาก - person Mulan; 01.11.2016
comment
@naomik ขอบคุณสำหรับเคล็ดลับของคุณ ฉันถามคำถามที่แม่นยำยิ่งขึ้นด้วยฝันร้ายที่นี่: stackoverflow.com/questions/40379389/cron- และ-ฝันร้าย - person Quentin Del; 02.11.2016

ปัญหาของฉันอยู่ในการตั้งค่าของ cron ฉันอยากจะใช้

var job = new CronJob('* 10 * * * *', function() {
    crawl()
  }, function () {
    console.log("crawl ended")
  },
  true
);

นอกจากนี้ ฉันยังต้องกำหนดการตั้งค่าฝันร้ายใหม่ให้กับฟังก์ชันของฉันด้วย

var get_data = function(){
  var Nightmare = require('nightmare');
  var nightmare = Nightmare({
    typeInterval: 300,
    show: true
  });
  nightmare
  .goto('https://pageThatRequireToLoginThenDiplayJsonAsText.com')
  .type('[name=email]', '')
  .wait(1000)
  .type('[name=email]', 'myemail')
  .wait(1000)
  .type('[name=password]', '')
  .wait(1000)
  .type('[name=password]', 'mypassword')
  .click('[type=submit]')
  .wait(25000)
  .wait(25000)
  .evaluate(function (page, done) {

    document.documentElement
    done()
  })
  .end()
  .then(function (result) {
    // fs.writeFileSync('testOutput.json', JSON.stringify(result));
    console.log(JSON.stringify(result))
  })
  .catch(function (error) {
    console.error('failed:', error);
  });
}

แทน

var Nightmare = require('nightmare');
var nightmare = Nightmare({
  typeInterval: 300,
  show: true
});

var get_data = function(){
  nightmare
  .goto('https://pageThatRequireToLoginThenDiplayJsonAsText.com')
  .type('[name=email]', '')
  .wait(1000)
  .type('[name=email]', 'myemail')
  .wait(1000)
  .type('[name=password]', '')
  .wait(1000)
  .type('[name=password]', 'mypassword')
  .click('[type=submit]')
  .wait(25000)
  .wait(25000)
  .evaluate(function (page, done) {

    document.documentElement
    done()
  })
  .end()
  .then(function (result) {
    // fs.writeFileSync('testOutput.json', JSON.stringify(result));
    console.log(JSON.stringify(result))
  })
  .catch(function (error) {
    console.error('failed:', error);
  });
}
person Quentin Del    schedule 04.11.2016