Web crawler - node.js crawler External call function cannot obtain variable value
習慣沉默
習慣沉默 2017-05-16 13:25:17
0
2
441

Recently I wanted to write a crawler novel to read, but I encountered some difficulties

console.log(catalogUrl) can print out the required URL

But what I expect is that when I call the function var xxx = getCatalogUrl(book) externally, I can get the value of the catalogUrl variable.
I tried return and global variables, but none of them work.

Help all the experts!

習慣沉默
習慣沉默

reply all (2)
淡淡烟草味

You need to understand js callback promise async/await

//简单的回调例子 asyncFunction(callback); function callback(data){ console.log(data) } function asyncFunction(cb){ setTimeout(function(){ cb && cb(1); //传递一个1出去 },300); }
    黄舟

    catalogUrl is in the asynchronous function! How to solve the asynchronous problem, look at these materials or Baidu, they are all basic things

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!