JS逆向爬虫需要掌握的最基础JS知识

一.JS逆向加密的地方

请求头,键和值都有可能加密

值加密

键和值加密

负载加密

 响应加密

url参数加密

cookie加密,一般有很多键值对

除此之外还要加速乐,瑞数,Akamai。

二.JS语法

1.变量数据类型

JS是一种弱类型语言,语法超级随意。var声明变量,还有const(声明后不能变),let。一共六种类型

//数字类型
var a =1
//字符类型
var b = '1'
//undefined
var c;
//布尔类型
var d = true
//空对象
var e = null
//复合类型
var f = [1,2,3,4]
var g = {"a":"1","b":"2"}
console.log(typeof a,typeof b,typeof c,typeof d,typeof e,typeof f,typeof g)

2.函数

输出

function a()
{
    console.log('aaaaaa')
}

返回

function b()
{
    return 'aaaaaaaaaaa'
}

返回多个数,取最后一个,返回333,这个重要

function c()
{

    return 111,222,333;

}

传参,缺失参数,正常输出

function d(a)
{

    console.log(a)
}
d(1,2,3)

参数都传到arguments,介于数组和对象之间

function d()
{

    console.log()
    console.log(arguments)
}
d(1,2,3)

自执行方法,自己执行

!function (){

    console.log('hhh')
}()

类似闭包,嵌套,输出hhh

!function (){

    function a()
    {
        console.log('hhh')
    }
    a()
}()

3.判断语句

等于 == ,会自动把两边转为数字进行毕竟,结果相等

aa = '1111'
bb = 1111
if (aa==bb){

    console.log('相等')
}

全等 === ,结果不相等

aa = '1111'
bb = 1111
if (aa===bb){

    console.log('相等')
}
else{
    console.log('不相等')
}

三目运算a大于b返回a,不然返回b,浏览器js的三目运算非常复杂,可以借助ai

//三目运算
 a = 1
b = 2
console.log(a>b?a:b)

4.控制流

加解密位置常在控制流里

var day = new Date().getDay()
switch (day)
{
    case 1:
        console.log('1')
        break
    case 2:
        console.log('2')
        break
    case 3:
        console.log('3')
        break
    case 4:
        console.log('4')
        break
    case 5:
        console.log('5')
        break
    case 6:
        console.log('6')
        break
    case 7:
        console.log('7')
        break
    
}

5.数组

//实例创建方式
arr1 = [1,"2","33333333333"]
//对象实例化
arr2 = new Array(1,2,3,"444444444444")
console.log(arr2)
//下标取值
console.log(arr1[1])
//获取长度
console.log(arr1.length)
//增加结尾值
arr1.push('1234')
console.log(arr1)
//删除结尾值
arr1.pop()
console.log(arr1)
//取零号位,并且删除
a = arr1.shift()
console.log(a)
console.log(arr1)
//指定删除,参数1:索引,参数2:删除个数,参数3:添加数据
arr1.splice(1,2,345,345,345,345)
console.log(arr1)

6.循环

var arr1 = [1,2,3,4,5]
for(var index = 0;index<arr1.length;index++) {
    console.log(arr1[index])
}
var a = 0
while(a<arr1.length)
{
    console.log(arr1[a])
    a++
}

7.对象(重要)

//实例化对象
object = {
    name:1,
    age:100,
    method:function () {console.log("hhh")}
}
//new一个对象
var object1 = new Object()
object1.name = "hhh"
object1.method = function () {console.log('wwww')}
//构造函数
function start(name,age)
{
    //this指对象本身,即start
    this.name = name//等于start.name
    this.age = age
    this.method = function () {console.log("xxxx")}
}
var object3 = new start("hhh","xxxx")

8.类

class object4
{
constructor(name,age) {
    this.name = name
    this.age = age
}
//私有属性
#arrt = 10
//静态属性,类里面定义方法直接名称
static sfun(){
    console.log("hhh")
}
//普通属性
    fun() {
        console.log("xxx")
    }

}
obj = new object4("xxx","hhhh")
console.log(obj.age)
obj.fun()

9.定时器

js是单线程,定时器就是指定时间执行,而不影响程序进行

function hhh()
{
    console.log("hhh")
}
//执行一次,500毫秒
setTimeout(hhh,500)
//执行多次
// setInterval(hhh,500)
console.log(111)
var st = setInterval(hhh,5000)
//关闭定时器
clearInterval(st)

结果如下:

10.promise(重要)

function a()
{

    return new Promise(
        function (res)
        {}

    )

}
console.log(a())

输出,为等待或挂起

.then用法

function a()
{
    return new Promise(
        function (resolve)
        {
            resolve ("hhhh")
        }

    )
}
a().then(
    function (data)
    {
        console.log(data)
    }
)
console.log("xxxxxxxxxxxxx")
console.log(a())
function a()
{
    return new Promise(
        function (resolve)
        {
            resolve ("hhhh")
        }

    )
}
a().then(
    function (data)
    {
        console.log(data)
    }
)
console.log("xxxxxxxxxxxxx")
console.log(a())

不影响程序运行,输出为:

11.async/await(重要)

function a()
{
    return new Promise(
        function (resolve)
        {
            resolve ("hhhh")
        }

    )
}
async   function main()
{
    var data = await a()
    console.log(data)

}
main()
console.log("xxxx")

输出结果如下

11.json

一般响应的json格式会转为字符串在进行加密,一般用于hook技术。

var a = {
    a:"1",
    b:"2"

}
//转为字符串
sringa = JSON.stringify(a)
console.log(typeof sringa)
console.log(a)
//转为json对象
JSONa = JSON.parse(sringa)
console.log(JSONa)

输出为

12.window对象

| `document.title`                    | 获取文档的title                        |
| :---------------------------------- | -------------------------------------- |
| `document.forms`                    | 获取所有form元素                       |
| `document.images`                   | 获取所有`img`元素                      |
| `document.links`                    | 获取所有a元素                          |
| `document.cookie`                   | 文档的cookie                           |
| `document.URL`                      | 当前文档的URL                          |
| `document.referrer`                 | 返回使浏览者到达当前文档的URL          |
| `document.write`                    | 页面载入过程中,用脚本加入新的页面内容 |
| `document.getElementById()`         | 通过id获取元素                         |
| `document.getElementsByTagName()`   | 通过标签名获取元素                     |
| `document.getElementsByClassName()` | 通过class获取元素                      |
| `document.getElementsByName()`      | 通过name获取元素                       |
| `document.querySelector()`          | 通过选择器获取元素,只获取第1个        |
| `document.querySelectorAll()`       | 通过选择器获取元素,获取所有           |
| `document.createElement()`          | 创建元素节点                           |
| `document.createTextNode()`         | 创建文本节点                           |
| `document.write()`                  | 输出内容                               |
| `document.writeln()`                | 输出内容并换行                         |
|                                     |                                        |

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值