抖音web端 s_v_web_id 参数生成分析与实现

一,通过js生成滑块s_v_web_id

function create_s_v_web_id() {
    var e = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("")
      , t = e.length
      , n = (new Date).getTime().toString(36)
      , r = [];

    r[8] = r[13] = r[18] = r[23] = "_",
    r[14] = "4";
    for (var o, i = 0; i < 36; i++)
        r[i] || (o = 0 | Math.random() * t,
        r[i] = e[19 == i ? 3 & o | 8 : o]);
    return "verify_" + n + "_" + r.join("")
}
此方法生成的s_v_web_id是不可以用来采集评论的,评论验证使用的s_v_web_id需要从页面取下来,然后在拿着过滑块

二,识别滑块

def calculate_distance(self, pic1_path, pic2_path):
    """
    计算滑块到缺口的距离
    """
    img1 = self.clear_white(pic1_path)
    img1 = cv2.cvtColor(img1, cv2.COLOR_RGB2GRAY)
    slide = cv2.Canny(img1, 100, 200)
    img2 = cv2.imread(pic2_path, 0)
    back = cv2.Canny(img2, 100, 200)
    slide_pic = cv2.cvtColor(slide, cv2.COLOR_GRAY2RGB)
    back_pic = cv2.cvtColor(back, cv2.COLOR_GRAY2RGB)
    x, y = self.template_match(slide_pic, back_pic)
    dis_x = int((x + 5) * (340 / 552))
    dis_y = int(y * (340 / 552))
    return dis_x, dis_y

def get_tracks(self, distance, _y):
    """
    获取轨迹参数
    """
    tracks = list()
    y, v, t, current = 0, 0, 1, 0
    mid = distance * 3 / 4
    exceed = random.randint(40, 90)
    z = random.randint(30, 150)
    while current < (distance + exceed):
        if current < mid / 2:
            a = 2
        elif current < mid:
            a = 3
        else:
            a = -3
        a /= 2
        v0 = v
        s = v0 * t + 0.5 * a * (t * t)
        current += int(s)
        v = v0 + a * t
        y += random.randint(-3, 3)
        z = z + random.randint(5, 10)
        tracks.append([min(current, (distance + exceed)), y, z])
    while exceed > 0:
        exceed -= random.randint(0, 5)
        y += random.randint(-3, 3)
        z = z + random.randint(5, 9)
        tracks.append([min(current, (distance + exceed)), y, z])
    tr = []
    for i, x in enumerate(tracks):
        tr.append({
            'x': x[0],
            'y': _y,
            'relative_time': x[2]
        })
    return tr

三,生成验证参数并验证

def captcha_verify(self, s_v_web_id, captchaBody):
    url = "aHR0cHM6Ly92ZXJpZnkuc25zc2RrLmNvbS9jYXB0Y2hhL3ZlcmlmeQ=="
    params = {
        "os_type": "2",
        "fp": s_v_web_id,
        "subtype": "slide",
    }
    data = {
        'captchaBody': captchaBody
    }
    r = self._parse_url(url=url, params=params, data=json.dumps(data))
    return r.json()

你可能感兴趣的:(前端,html,javascript)