问题描述
我试图使用Cheerio从特定的父元素中获取某个HTML类的子元素。这是我的代码:
const $ = cheerio.load(validHtmlBody);
var sections = $(".zloOqf").find(".fl").length;
return res.status(400).send(sections);
但是,此代码被拒绝,并出现UnhandledPromiseRejectionWarning
错误:
(node:60502) UnhandledPromiseRejectionWarning: RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: 1
at ServerResponse.writeHead (_http_server.js:208:11)
at ServerResponse.writeHead (index.js:44:26)
at ServerResponse._implicitHeader (_http_server.js:199:8)
at ServerResponse.end (_http_outgoing.js:717:10)
at ServerResponse.send (/node_modules/express/lib/response.js:221:10)
at index.js:41:30
at processTicksAndRejections (internal/process/next_tick.js:81:5)
(node:60502) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:60502) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
将此代码放入try catch块中并返回错误只会返回一个空的json。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)