首页 > 解决方案 > 在 google dialogflow fullfilment 中使用 node.js 文档未定义(服务器端)

问题描述

function readrequestfromdb(agent){
  var links = [];
  var requestbooks = [];
  var books = admin.database().ref( 'data/request' );
  const Nightmare = require( 'nightmare' );
  const nightmare = Nightmare();
  const url = 'https://www.flipkart.com/';
  return books.once( "value", function( data ){
    var _data = data.val();
    for( var key in _data ){
      var book = _data[key];
      var name = book.name;
      var author = book.author;
      var res = `name is ${name} and author is ${author}`;
      requestbooks.push( res );
      nightmare
        .goto( url )
        .wait( 'body' )
        .click( 'button._2AkmmA._29YdH8' )
        .type( 'input.LM6RPg', name )
        .click( 'button.vh79eN' )
        .wait( 'div.bhgxx2' )
        .evaluate( () => document.querySelectorAll( 'a._2cLu-l' )[0].href )
        .end()
        .then( link => {
          console.log( link );
          links.push( link );
        } )
        .catch( err => {
          console.log( err );
        } );

    }

    return agent.add( text );
  } );
}

我正在尝试使用上述代码进行网络抓取,并且在噩梦文档中给出了访问文档。什么是解决方案。

标签: javascriptnode.jsdialogflow-esdialogflow-es-fulfillmentnightmare

解决方案


推荐阅读