KOA2 await is not valid and is not waiting

router.get ("/ spider", async (ctx, next) = > {
var titles = []
await request ({

)
url:"http://caipiao.163.com/award/cqssc/",
gzip: true,
method:"GET"

}, function (e _ r _ b) {

  // console.log(b)
if(!e){
  var $ = cheerio.load(b);
  $(".award-winNum").each(function (idx, element) {
    var $element = $(element);
    // console.log($element.text())
    titles.push({
      title: $element.text()
    })
  })
  console.log(titles)
}

})
ctx.body = titles;
})

await is not waiting. May I ask how to solve the problem?

later Baidu solved the problem:
router.get ("/ spider", async (ctx, next) = > {
var that = ctx;

)

let postData = await spider (ctx)
ctx.body = postData;

})

function spider ()
{
return new Promise ((resovle, reject) = > {

try{
  var titles = [  ]
  request({
    url:"http://caipiao.163.com/award/cqssc/",
    gzip: true,
    method:"GET"
  },function(e,r,b){
      // console.log(b)
    if(!e){
      var $ = cheerio.load(b);
      $(".award-winNum").each(function (idx, element) {
        var $element = $(element);
        // console.log($element.text())
        titles.push({
          title: $element.text()
        })
      })
      resovle(titles);   
    }
  })
} catch (err) {
  reject(err);
}

});

Mar.01,2021

  1. await must be followed by promise, 's first version of request or callback
  2. the second is also wrong
function spider() {
    return new Promise((resolve,reject)=>{
        request(xxx,(e,r)=>{
            e?reject(e):resolve(r);
        });
    });
}

use

try{
    await spider();
}catch(e){
    console.log(e);
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c7a4-2c345.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c7a4-2c345.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?