在html里面设置cookie

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<script>
// 设置cookie的函数
function setCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

// 调用函数设置cookie
setCookie("FSSBBIl1UgzbN7N80S", "s1LcNviQmjHdZZfJlqwSLqHvW1Z5teVJ.1m3snnntsvyT1hOPvuiOUp5nQ7l.t24", 7);
setCookie("www.fangdi.com_http_ic", "www.fangdi.com.cn_80_RS", 7);
</script>

自执行函数

作用:匿名自动执行

1
2
3
4
5
(function(){ /* code */ }());
!function(){ /* code */ }();
~function(){ /* code */ }();
-function(){ /* code */ }();
+function(){ /* code */ }();

cxs && dosomething 相当于 if cxs: dosomething

var let const 区别:

  • var 声明的变量属于函数作用域,let 和 const 声明的变量属于块级作用域

  • let 变量可以改变

  • const 变量不能改变,常用于声明常量

  • a = 2 什么都不适用,默认为全局变量

axios 发起请求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const axios = require('axios').default;


resp = await axios.get('http://proxy.ip.dataduoduo.com/api/v1/proxy/get', {
params: {
taskId: taskId,
payType: 1,
supplierCode: `${useAgent}`
},
headers: {
Authorization: `cdba2705-d935-494c-9b67-645d9271590b`
},
timeout: 10000
});

request库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const request = require('request');

// 封装Promise对象
getRequest(opts) {
return new Promise((resolve, reject) => {
request.get(opts, function (err, response, body) {
if (!err) {
if (body !== 'null') {
let results = {
body: body,
response: response
};
resolve(results);
} else {
reject(err);
}
} else {
reject(err);
}
});
});
}

postRequest(opts) {
return new Promise((resolve, reject) => {
request.post(opts, function (err, response, body) {
if (!err) {
if (body !== 'null' && body !== "" && body) {
let results = {
body: body,
response: response
};
resolve(results);
} else {
reject(err);
}
} else {
reject(err);
}
});
});
}

// 调用
var options = {
'method': 'POST',
'url': url,
'headers': {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"dataList": [post_data],
"sourceId": "1"
})

};
let res = await this.postRequest(options);

Promise

JavaScript中的Promise是一种处理异步操作的方式。它可以将异步操作封装成一个Promise对象,然后可以通过链式调用的方式来处理异步操作的结果。

浏览器指纹,其实就是 webAPI,相似的还有 nodeAPI

11个常见的JavaScript语法糖写法

语法糖

1
2
3
let {name} = cxs
// 相当于
let name = cxs.name

浏览器插桩操作

本质就是:Edit breakpoint 来代替 console.log 输出,运行到这里就会自动输出日志

image.png

JSDOM

jsdom 中文文档 - 掘金

基本使用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const jsdom = require("jsdom");
const fs = require("fs");

const JSDOM = jsdom.JSDOM;
const options = {
url: "https://match.yuanrenxue.cn/match/2",
referrer: "https://match.yuanrenxue.cn/match/2",
contentType: "text/html; charset=utf-8",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
includeNodeLocations: true,
runScripts: "dangerously", // 允许执行 script 标签
};

var getCookie = function (){
const data = fs.readFileSync('yrx.html'); // 同步读取文本
const dom = new JSDOM(data, options);
let ck = dom.window.document.cookie;
dom.window.close();
return ck;
}

console.log(getCookie())

通用头部

1
2
3
4
5
6
7
8
9
10
11
12
const {
JSDOM
} = require("jsdom");
const dom = new JSDOM("<!DOCTYPE html><p>Hello world</p>");

window = dom.window;
document = window.document;
navigator = window.navigator;
location = window.location;
history = window.history;
screen = window.screen;
alert = window.alert;
  • 去掉 try ... catch ... 语句,只保留 try,才能捕获到报错信息

  • 国内下载加速:

    • cnpm install canvas
    • cnpm install jsdom