1 Star 0 Fork 3

lebu9527/puppeteer+koa爬虫程序

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
request-log.js 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
钟鹏 提交于 2024-08-17 10:36 +08:00 . feat: 创建爬虫程序
const fs = require('fs')
const path = require('path')
// 格式化时间戳
const formateDate = (date, rule = '') => {
let fmt = rule || 'yyyy-MM-dd hh:mm:ss'
// /(y+)/.test(fmt) 判断是否有多个y
if (/(y+)/.test(fmt)) {
// RegExp.$1 获取上下文,子正则表达式 /(y+)/.test(fmt)
fmt = fmt.replace(RegExp.$1, date.getFullYear())
}
const o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
}
for (let k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
const val = o[k] + ''
fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? val : ('00' + val).substr(val.length))
}
}
return fmt
}
const writeLog = (logData, fileName, times) => {
const writeFilePath = path.join(__dirname, `logs/${fileName}`);
let content = formateDate(new Date())
if (times) {
content += `(${times})`
}
content += ':\r' + JSON.stringify(logData) + '\n';
fs.appendFileSync(writeFilePath, content);
}
module.exports = writeLog
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lebu2018/puppeteer_koa.git
git@gitee.com:lebu2018/puppeteer_koa.git
lebu2018
puppeteer_koa
puppeteer+koa爬虫程序
master

搜索帮助