javascript - 如何在javascript中迭代多个标头
问题描述
当我想在下载文件时只获取第一个“日期”标题时,我无法迭代选择第一个,5 个“日期”标题出来了。
Tue, 20 Aug 2019 17:40:36 GMT
Tue, 20 Aug 2019 17:40:37 GMT
Tue, 20 Aug 2019 17:40:37 GMT
Tue, 20 Aug 2019 17:40:37 GMT
Tue, 20 Aug 2019 17:40:37 GMT
我试过用headers.entries(),用for,foreach,都没有成功。
await Promise.all([
await button.click(),
page.on('response', response => {
console.log(response._headers['date']);
})
]);
解决方案
尝试这样的事情:
var firstdate = null;
await Promise.all([
await button.click(),
page.on('response', response => {
firstdate = firstdate == null ? response._headers['date'] : firstdate;
console.log(response._headers['date']);
})
]);
console.log("first date", firstdate);
如果你只想在第一次采取行动,你可以做更多这样的事情
var firstdate = true;
await Promise.all([
await button.click(),
page.on('response', response => {
firstdate && console.log(response._headers['date']); // can replace console.log with your action
firstdate = false;
})
]);
推荐阅读
- pypi - 在 PyPi 上更新包的指南
- ios - 我无法推送,因为本地存储库已过期,但我无法提取数据
- go - 使用golang解压密码zip
- .net - 正在使用什么版本的.Net
- react-native - 在 React Native 实时服务器 Web 服务中获取网络请求失败
- wso2 - 更改 WSO2 服务器主密钥库中的证书
- angularjs - angularjs/angular 6 混合应用程序中的 TS2430 错误
- oracle - 如何循环使用 SYS_REFCURSOR 类型的存储过程记录
- vue.js - 如何使用 Webpack 在 VueJS 中预渲染初始页面?
- javascript - 我的自定义指令无法正常工作