有这个代码:
const fs = require('fs');
const axios = require('axios');
const cheerio = require('cheerio');
const parseBilanzGuv = async (param) => {
let link = 'https://www.finanzen.net/suchergebnis.asp?_search=' + param;
try{
await axios.get(link)
.then(res => res.data)
.then(res => {
let html = res;
$ = cheerio.load( html, { decodeEntities: false } );
return {symbol: 'значение'};
})
.catch(err => console.log(err));
}
catch(e){
console.log("err- ", e);
}
};
parseBilanzGuv('US30161N1019').then(function(result) {
console.log(result); // undefined
});
当我尝试从函数中获取返回值时parseBilanzGuv(),我得到了undefined.
问题:
需要在代码中进行哪些更改才能提取出symbol: 'значение';可能的值?
如果我没记错的话,你不会从
parseBilanzGuv(). 替换beforereturn以返回结果 Promise。awaitaxios.get(link)虽然最好不要混合使用 promise 和 async/await 链,也就是说,将链替换为 await 系列并 return already
{symbol: 'значение'},这样会更加一致。