NodeJs抓取页面

npm i cheerio request iconv-lite 思路:通过 request 获取到页面。在使用 iconv-lite 编译数据。在使用 cheerio 拿到对应的元素。这里以抓取微博热搜为例 const cheerio = require('cheerio'); const request = require('request'); const iconv = require('iconv-lite'); function http(url, decode = 'utf8') { return new Promise((resolve, rejext) => { request({ url, encoding...

read more..

随机数

function getRandom(start, end, fixed = 0) { let differ = end - start let random = Math.random() return (start + differ * random).toFixed(fixed) } getRandom(1,5) 1<= num >=5

read more..

保存图片文件,下载图片

function downloadIamge(imgsrc, name) { //下载图片地址和图片名 let image = new Image(); // 解决跨域 Canvas 污染问题 image.setAttribute("crossOrigin", "anonymous"); image.onload = function () { let canvas = document.createElement("canvas"); canvas.width = image.width; canvas.height = image.height; ...

read more..

赛邮云通信SUBMAIL

NodeJs发送短信 var request = require('request'); let post = function (url, postdata) { let options = { url: url, formData: postdata }; return new Promise(function (resolve, reject) { request.post(options, function (err, response, body) { if (err) { reject(err) } else { resolve(b...

read more..

粘贴图片 ctrl+v

document.addEventListener("paste", function (event) { var isChrome = false; if (event.clipboardData || event.originalEvent) { //某些chrome版本使用的是event.originalEvent var clipboardData = event.clipboardData || event.originalEvent.clipboardData; if (clipboardData.items) { // for chrome var items = c...

read more..

JS判断是否为IE浏览器

function IEVersion() { var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器 var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器 var isIE11 = userAgent.in...

read more..

复制到剪切板

copy(val) { let oInput = document.createElement("input"); oInput.value = val; document.body.appendChild(oInput); oInput.select(); document.execCommand("Copy"); this.$message({ message: "复制成功", type: "success", }); oInput.remove(); },

read more..

正则

数字 data = data.replace(/[^\.\d]/g, "") // 数字 data = data.replace(".", "") // 去掉小数点 小数两位 data = data.replace(/[^\.\d]/g,"") // 数字 data = data.replace(/^(\-)*(\d+)\.(\d\d).*$/,"$1$2.$3") // 小数点后 视频图片 var reg = /\.(png|jpg|gif|jpeg|webp)$/; /(mp4|avi|mov|mkv|flv)$/ reg.test(fileName) 去除空格&nbsp; text = text.re...

read more..

JS-Cookie

function getCookie(cookie_name) { var allcookies = document.cookie; var cookie_pos = allcookies.indexOf(cookie_name); if (cookie_pos !== -1) { cookie_pos = cookie_pos + cookie_name.length + 1; var cookie_end = allcookies.indexOf(";", cookie_pos); if (cookie_end === -1) { cookie_end = allcookies.len...

read more..