1.1.4 • Published 3 years ago

get_bing_image v1.1.4

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

概述

抓取必应壁纸

安装

npm i get_bing_image -g

命令行使用

get_bing_image

源码学习

#!/usr/bin/env node
/* 请求 */
const got = require('got')
/* 页面 */
const cheerio = require('cheerio')
/* 文件 */
const stream = require('stream')
const promisify = require('util').promisify
const pipeline = promisify(stream.pipeline)
const fs = require('fs')

let urlHtml = 'https://cn.bing.com/'
/* 请求 */
got(urlHtml).then(handle).catch(() => console.log(`请求${urlHtml}失败`))
/* 页面 */
function handle(text) {
	const $ = cheerio.load(text.body)
	let style = $('div.img_cont').attr('style')
	const reg = /url\((.*)\)/
	let attr = reg.exec(style)[1]
	downOne(attr, process.cwd(), `today.jpg`)
}
/* 文件 */
function downOne(url, dir, filename) {
	pipeline(
		got.stream(url),
		fs.createWriteStream(dir + "/" + filename)
	)
}

发现Bug请联系

a18752140506@163.com

1.1.4

3 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago