某查信息获取cookie限制

地址链接

游客状态

反爬类型
  • 基于cookie和IP的访问频率(次数)限制
反爬策略
  • 游客状态
  • 基于IP的访问频率限制
  • 搜索接口有动态加密参数mfccode,mfccode只能使用一次
  • cookie中有游客id(qznewsite.uid)标识游客身份
  • 基于代理池解决IP问题
  • 模拟生成游客id
  • 模拟生成mfccode

mfccode 追踪

  • 全局搜索 mfccode

  • 找返回的值的函数体部分代码,控制台打印

  • 确定生成的值的全部函数

var window = {'document': {'cookie': 'qznewsite.uid=vplfbrwhxcxk25nktmburpax'}};
(function (w) {
    var s = function (a) {
            if (!a) {
                return '';
            }
            var al = a.length, ret = new Array(al), i = 0, j = i;
            while (al--) {
                ret[j++] = String.fromCharCode(a[i++])
            }
            return ret.join('');
        }, ex = function (x, y) {
            for (n in y) {
                x[n] = y[n]
            }
        }, ck = function (sn) {
            var ac = w.document[s([99, 111, 111, 107, 105, 101])].split('; ');
            for (var i = 0; i < ac.length; i++) {
                var aCrumb = ac[i].split('=');
                if (sn == aCrumb[0]) {
                    if (aCrumb[1] != null && aCrumb[1] != typeof undefined) {
                        return unescape(aCrumb[1]);
                    }
                    ;
                    return '';
                }
            }
            ;
            return typeof undefined;
        }, le = s([108, 101, 110, 103, 116, 104]), pc = s([99, 104, 97, 114, 67, 111, 100, 101, 65, 116]),
        id = ck(s([113, 122, 110, 101, 119, 115, 105, 116, 101, 46, 117, 105, 100])), mov = function () {
            var lto1 = function (l1, t7) {
                return l1 & t7
            }, ouk4 = function (o4, u1) {
                return o4 | u1
            }, iga4 = function (i5, g2) {
                return i5 >> g2
            }, dcs7 = function (d8, c7) {
                return d8 << c7
            }, wxu7 = function (w4, x2) {
                return w4 - x2
            }, umk4 = function (u0, m4) {
                return u0 + m4
            }, biv0 = function (b6, i3) {
                return b6 * i3
            }, __x = 147;
            return wxu7(wxu7(wxu7(dcs7(umk4(wxu7(iga4(wxu7(umk4(umk4(ouk4(wxu7(umk4(lto1(iga4(iga4(wxu7(umk4(iga4(dcs7(ouk4(lto1(lto1(dcs7(umk4(dcs7(iga4(dcs7(biv0(umk4(iga4(umk4(ouk4(lto1(biv0(ouk4(wxu7(ouk4(wxu7(wxu7(biv0(iga4(lto1(biv0(dcs7(lto1(wxu7(umk4(lto1(iga4(iga4(umk4(ouk4(iga4(dcs7(wxu7(lto1(umk4(dcs7(lto1(biv0(umk4(ouk4(ouk4(umk4(lto1(biv0(iga4(ouk4(dcs7(wxu7(wxu7(umk4(wxu7(wxu7(dcs7(dcs7(lto1(wxu7(dcs7(biv0(iga4(wxu7(wxu7(wxu7(iga4(iga4(iga4(umk4(ouk4(wxu7(dcs7(iga4(ouk4(biv0(umk4(ouk4(lto1(ouk4(ouk4(iga4(dcs7(ouk4(ouk4(ouk4(iga4(lto1(biv0(iga4(lto1(biv0(dcs7(ouk4(ouk4(umk4(dcs7(iga4(biv0(wxu7(ouk4(biv0(lto1(umk4(dcs7(umk4(biv0(biv0(umk4(dcs7(dcs7(wxu7(dcs7(biv0(umk4(wxu7(iga4(umk4(biv0(umk4(umk4(iga4(lto1(ouk4(wxu7(ouk4(biv0(umk4(biv0(dcs7(biv0(lto1(wxu7(wxu7(wxu7(ouk4(iga4(wxu7(umk4(dcs7(dcs7(ouk4(wxu7(lto1(biv0(ouk4(ouk4(umk4(dcs7(umk4(umk4(umk4(iga4(iga4(iga4(umk4(wxu7(iga4(dcs7(iga4(biv0(iga4(biv0(iga4(umk4(iga4(lto1(ouk4(lto1(umk4(ouk4(umk4(ouk4(iga4(iga4(umk4(ouk4(ouk4(biv0(biv0(iga4(iga4(iga4(wxu7(umk4(umk4(umk4(dcs7(biv0(wxu7(iga4(umk4(wxu7(ouk4(wxu7(lto1(dcs7(lto1(dcs7(biv0(dcs7(umk4(iga4(lto1(biv0(ouk4(lto1(lto1(umk4(iga4(iga4(ouk4(iga4(ouk4(dcs7(ouk4(wxu7(umk4(wxu7(dcs7(wxu7(ouk4(umk4(iga4(biv0(wxu7(ouk4(biv0(dcs7(ouk4(umk4(iga4(biv0(umk4(dcs7(dcs7(biv0(dcs7(biv0(dcs7(iga4(ouk4(lto1(wxu7(iga4(umk4(iga4(biv0(ouk4(biv0(dcs7(lto1(umk4(ouk4(dcs7(lto1(lto1(umk4(dcs7(wxu7(umk4(iga4(dcs7(iga4(biv0(lto1(dcs7(wxu7(lto1(umk4(dcs7(ouk4(iga4(umk4(lto1(wxu7(iga4(ouk4(lto1(lto1(umk4(umk4(wxu7(lto1(wxu7(biv0(ouk4(wxu7(biv0(ouk4(lto1(ouk4(ouk4(wxu7(umk4(ouk4(ouk4(iga4(umk4(wxu7(iga4(ouk4(umk4(iga4(dcs7(biv0(wxu7(umk4(ouk4(ouk4(iga4(lto1(dcs7(iga4(wxu7(iga4(ouk4(iga4(wxu7(wxu7(iga4(dcs7(umk4(lto1(biv0(umk4(iga4(biv0(lto1(ouk4(umk4(wxu7(ouk4(dcs7(ouk4(dcs7(ouk4(wxu7(wxu7(ouk4(wxu7(umk4(wxu7(biv0(lto1(ouk4(biv0(wxu7(umk4(iga4(biv0(lto1(wxu7(iga4(lto1(wxu7(iga4(umk4(ouk4(wxu7(lto1(biv0(biv0(umk4(dcs7(wxu7(umk4(iga4(umk4(lto1(wxu7(wxu7(iga4(wxu7(biv0(ouk4(umk4(lto1(wxu7(lto1(lto1(biv0(iga4(umk4(ouk4(umk4(iga4(ouk4(ouk4(wxu7(ouk4(biv0(lto1(wxu7(lto1(wxu7(wxu7(lto1(wxu7(lto1(wxu7(lto1(biv0(biv0(ouk4(ouk4(lto1(wxu7(lto1(lto1(iga4(ouk4(lto1(biv0(ouk4(wxu7(iga4(ouk4(wxu7(iga4(wxu7(dcs7(ouk4(biv0(lto1(wxu7(umk4(lto1(ouk4(iga4(umk4(umk4(umk4(dcs7(biv0(lto1(ouk4(lto1(umk4(iga4(iga4(ouk4(wxu7(iga4(lto1(biv0(lto1(iga4(umk4(lto1(wxu7(umk4(wxu7(ouk4(wxu7(dcs7(wxu7(lto1(umk4(iga4(dcs7(wxu7(dcs7(ouk4(iga4(lto1(biv0(iga4(iga4(biv0(umk4(iga4(iga4(umk4(iga4(lto1(umk4(ouk4(ouk4(umk4(dcs7(iga4(iga4(biv0(iga4(iga4(biv0(iga4(dcs7(iga4(umk4(umk4(iga4(__x, 1), 3434), -425), 4), 4), 2), 4), 2), 2), 4), 3), 3), 1), 195), 3238), 2758), 2565), 64620), 2), -1792), 1), 4), 1989), 3), 1), 3), 3), 59500), 2), 258), 4), 1156), 4), 1), 333), 17548), 636), 3), 1453), 2428), -849), -519), -3558), 34633), 3134), 1), 10284), 3), 56084), 1), 2129), 4014), 2), 2), -2034), 57309), 428), 5296), 4), 1), 3803), -3044), 98), 1), 3515), 24122), -550), -923), 5666), 4), 1898), 4), 618), 3), 2832), 280), 2), -1498), 2161), 4), 29965), 1375), 2), 18309), 32735), 3500), 27643), 2631), 1560), 3), 4), 57340), 1968), 55316), 3825), 21026), -3945), -2681), 8110), 2041), 24692), 4), 2813), -3329), 2464), 1451), 2), 3717), 3113), 2169), 4), 4), 63828), 53094), -336), 37406), -2242), 2599), 1), 729), 4), 1343), -616), 52625), -2062), 1), -9), 3787), 1), 1030), 2), 1), 14389), -1686), 1781), 776), 2), 2451), 24257), 2), 4026), 61401), 3), 3), 1713), 2473), 3), 860), 61739), 1), -323), 930), 3772), 2490), -858), -3974), 3120), 4), 4018), 1), 2785), 3892), -2189), 3454), 7617), 4), 2), 2102), 1), 62039), 3531), 3), 2), -2251), 2550), 4), 3508), 3), -3029), 4), 4), 18041), 2), 768), 2759), -548), -1053), 3), 3), 4), -835), 3832), 1), 740), 698), 4), 3090), 1670), -3559), -3719), 593), 2492), 11347), 1224), 3), 590), 2581), 4), 3340), 25339), 3990), -3728), -2038), 36206), 37471), 1409), 2), 3468), 5093), -918), 4), 1406), 4), -3409), 45074), -2588), 4), 46342), 3), 3), 1), 2), 2982), -2570), 1), -2874), 24545), 25192), 4), 666), 1308), 10149), 2), 3), 2235), 2), 3), -726), 2), 464), 61490), 3031), 1), 1), 2), 1), 2), 3), 2), 1093), 3), 4), 3138), 1048), 2), 1), 515), -2486), 1), 2), 3636), 1121), 2567), 1), -1646), -3733), 701), 1317), 4), 2743), 1), 2381), 2), 4), -2248), 22183), 51115), 3959), 2), 21011), 2), -3933), 4), 1), 4), 15391), 4), 56098), -3879), 3609), -256), 3491), 4), -444), 3), 1), -1158), 3722), 1415), 1334), 3), 1), 3), 4), 3), 3942), 3534), -3382), 1), 3), 1838), 1925), 2811), -3780), 59420), 2476), 6132), 3), 3235), 1), 2), 2), 2), 1), 1), 1), 1060), -3960), 3), 4), 4), -4015), -2992), 543), 2), 459), 1970), 1483), 4), 26641), 3298), 3416), 3), 1), -590), -1431), 3), 392), 208), 2753), 3703), 10340), 4), 4), 3), 1904), 1), 2303), -2047), 1601), 61116), 4), 1903), 3581), 3), -1220), 4), -2499), 665), 2), 3), -1539), 3), 2), -3759), 4), 4), -1861), 4), -2338), 30686), 2), 3285), -3997), 2), 3), 1), -2632), 1182), 2148), 3), 4), 8441), 3), 4), 20940), 3), 3660), 3800), 2172), 2), 3), 1275), 3134), 58479), 859), 832), 1), 510), 3), 2), -4030), 875), 1741), 1), 4), 1), 3883), -2317), 89), 3), 4), 3), 3155), 31627), 3), 1), 2934), -131), -454), 3382), 1529), 4), 3853), 4), 2), 6153), 1321), 905), 4092), -2274), 1), 56477), 2), -1675), 48676), 2297), 3), 1), 2087), -2405), 4), 4), 25297), -104), -3641), 4436), 4), 1), 37892), 1), 1), -2338), -3598), 2490), -490), 1126), 4), 5192), 3607), -3788), 3), 1585), 1), 2), 2), 1), 3125), 2), 22108), 48814), 1890), 4), 3), 945), 3903), 4), 2), 24603), -404), 3571), 1266), 1804), 547), -3475), 3), -1509), -1344), 1), -2020), -889), 1951);
        },
        sk = [-43, -49, 23, 131, 159, -48, 16, -33, 93, 30, 41, 4, 59, -75, -67, -8, -2, 141, 19, 32, -9, 111, 158, -20, 86, 32, -49, -81, -103, -2, -88, 80, 15, -79, 124, -43, 176, 73, 52, -33, 88, 151, 51, 34, 102, -51, -104, -46, 9, 97, -71, 142, -35, -7, -20, -21, 91, 48, 9, -49, -67, 37, -69, -6, 88, 42, 138, 79, 11, -84, 38, -19, 46, -49, -4, -48, -95, -107, -50, 151, -26, 89, -16, -59, -35, -21, 7, -28, 44, 137, 93, -5, 26, -70, 60, 88, -90, -70, 56, 39, 149, 4, -8, -23, 69, 144, 19, 31, 68, -66, 19, 114, 100, 144, 28, -43, 94, 71, 163, -32, 63, 17, 109, 73, 54, 137, 85, 72, 93, 104, 102, 9, 166, 107, 91, -31, 42, 25, 135, -79, -33, 101, 117, 135, 121, 37, -47, 70, 205, 135, 65, -26, 57, 63, -3, 23, 120, 114, 58, 111, -84, 109, -24, -62, 144, 132, 57, -27, 86, -17, -26, -45, 88, 85, 141, 136, -44, 76, -92, 50, 47, 89, 141, -18, 70, 26, 116, -91, 113, -2, 130, -46, -91, -29, 98, 26, -44, -79, 17, -32, 88, 112, 90, -83, -17, 15, 25, -3, -66, 75, -51, 154, -37, 16, 198, -22, 90, 156, 82, 133, -71, -90, 101, 91, 114, -69, -37, -63, 124, -88, 194, -31, 59, 185, -45, 48, 72, 8, 123, -9, 118, 66, 9, -54, 152, -9, 203, -33, 70, 34, 20, 9, -41, -75, 71, -18, -24, 89, -19, 98, -29, -23, 110, -21, 50, 159, -52, 59, 72, -11, 86, 148, 59, 61, 146, -35, 54, 0, 178, -30, 45, 136, 117, -75, -105, 24, 26, -47, 131, 19, -25, -83, 114, 53, 93, -27, 40, 23, -84, -53, 102, 79, -76, 99, -76, -81, 19, -18, 60, -27, 85, -33, 86, 57, 56, 7, -80, -5, 12, 174, -43, 148, 120, -44, -4, 147, 57, -29, 91, -36, 55, -63, 27, 67, 66, 99, 45, 92, 120, 54, 14, -46, 122, -32, 41, -38, 134, 30, 16, 72, 85, 77, 80, -76, -79, 0, 22, -23, -13, -23, 79, 75, 54, 56, -106, -65, 9, 138, -67, 56, 92, -88, 97, -66, 145, -19, 35, 136, 38, 94, -8, 19, 13, 117, 93, -29, 144, -80, 43, 44, -6, -25, 55, -3, 128, -69, -14, 95, -100, 180, -27, -76, 143, 58, -9, 42, 95, -32, 46, 195, 61, -69, 46, 122, -42, 29, 21, 94, -9, -83, -44, 21, -13, -29, 53, 72, -84, -60, -24, 124, 44, 186, 27, 119, 101, 82, 75, 65, 175, -21, 92, 77, 15, 113, 29, 52, 5, -6, 138, 11, -57, 1, 90, 114, 182, -23, 69, -42, 139, 6, 121, -45, 9, 16, -53, -76, -91, 136, -29, -40, 142, -28, 76, -4, 95, -5, -110, -69, 125, 155, 82, -4, -24, 130, 120, -59, 86, -25, 84, 139, -106, 110, 35, 108, -7, 187, 121, -61, -24, -81, 158, -39, 41, -33, 91, 34, 95, 23, 6, 97, 143, 29, 33],
        m = function (a, k, i) {
            return (a + k[pc](k[le] % i))
        }, dc = function () {
            var sl = sk[le] - 1, av = sk[sl], i = 0, j = i, ret = i, a, b;
            while (sl--) {
                i = j;
                b = m(sk[j++], id, (j > 0 && j % 0x10 == 0) ? 0x10 : j % 0x10);
                if (i % 5 == 0) {
                    ret -= (b * (i % 3) - av)
                } else {
                    ret += (b + 95)
                }
            }
            return ret | mov(1)
        };
    w[s([95, 95, 113, 122, 109, 99, 102])] = dc
})(window);

function getMfccode() {
    return window.__qzmcf()
}

console.log(getMfccode())
结果

游客id获取
def fetch_uid():
    headers = {
        'Host': 'www.qichamao.com',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'Sec-Fetch-Site': 'cross-site',
        'Sec-Fetch-Mode': 'navigate',
        'Sec-Fetch-Dest': 'document',
        # 'Referer': 'https://www.baidu.com/link?url=7YjEAr3q_1WtGisES1BtXFA2cGO0cSxYzMNM3aT6lZMNM9T3_e29lwbwuSyFjHZA&wd=&eqid=8906deea0001782b00000003621c88fd',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }
    response = requests.get('https://www.qichamao.com/', headers=headers)
    uid = response.cookies.get('qznewsite.uid')
    return uid
模拟mfccode
def get_js_verify_code(uid):
    headers = {
        'Connection': 'keep-alive',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'Accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01',
        'X-Requested-With': 'XMLHttpRequest',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
        'sec-ch-ua-platform': '"Windows"',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
        # 'Referer': 'https://www.qichamao.com/search/all/%E6%88%BF%E5%A4%A9%E4%B8%8B?mfccode=65761',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }
    timestamp = int(time.time() * 1000)
    params = (
        ('t', random.random()),
        ('_', timestamp),
    )
    cookies = {
        'qznewsite.uid': uid,
    }
    response = requests.get('https://www.qichamao.com/home/GetJsVerfyCode', headers=headers, params=params,
                            cookies=cookies)
    return response.text
# uid为上面生成的游客id
def get_mfccode(uid):
    js_code = get_js_verify_code(uid)
    prefix = """
                    var window = {'document': {'cookie': 'qznewsite.uid=%s'}};
                    """ % (
        uid,)
    tail = """
                function getMfccode(){
                    return window.__qzmcf()
                }
                """
    js_code = prefix + js_code + tail
    ctx = execjs.compile(js_code)
    mfccode = ctx.call("getMfccode")
    return mfccode
搜索页
# uid为游客id
# mfccode 为上面生成的mfccode
# search_word为搜索公司名
def fetch_list(uid, mfccode, search_word):
    cookies = {
        'qznewsite.uid': uid,
    }
    headers = {
        'Connection': 'keep-alive',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'navigate',
        'Sec-Fetch-User': '?1',
        'Sec-Fetch-Dest': 'document',
        # 'Referer': 'https://www.qichamao.com/search/all/%E6%88%BF%E5%A4%A9%E4%B8%8B?mfccode=65761',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }
    params = (
        ('mfccode', mfccode),
    )
    response = requests.get(f'https://www.qichamao.com/search/all/{search_word}', headers=headers,
                            params=params, cookies=cookies)
    return response

登录破解验证

登录方式login_flow.py
import time
import ddddocr
import requests


def fetch_uid():
    headers = {
        'Host': 'www.qichamao.com',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.'
                      '4692.99 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,'
                  'application/signed-exchange;v=b3;q=0.9',
        'Sec-Fetch-Site': 'cross-site',
        'Sec-Fetch-Mode': 'navigate',
        'Sec-Fetch-Dest': 'document',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }

    response = requests.get('https://www.qichamao.com/', headers=headers, timeout=6)
    uid = response.cookies.get('qznewsite.uid')
    return uid


def get_verify_code_image(cookies):
    headers = {
        'Connection': 'keep-alive',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                      'Chrome/97.0.4692.99 Safari/537.36',
        'sec-ch-ua-platform': '"Windows"',
        'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'no-cors',
        'Sec-Fetch-Dest': 'image',
        'Referer': 'https://www.qichamao.com/',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }

    params = (
        ('0.8259782243872622', ''),
    )

    response = requests.get('https://www.qichamao.com/usercenter/varifyimage', headers=headers, params=params,
                            cookies=cookies)
    return response


def identify_verify_code(response):
    ocr = ddddocr.DdddOcr()
    verify_code = ocr.classification(response.content)
    return verify_code


def login(account, password, verify_code, cookies):
    headers = {
        'Connection': 'keep-alive',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
                      ' Chrome/97.0.4692.99 Safari/537.36',
        'sec-ch-ua-platform': '"Windows"',
        'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'no-cors',
        'Sec-Fetch-Dest': 'image',
        'Referer': 'https://www.qichamao.com/',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }

    data = {'sevenDays': True,
            'userId': account,
            'password': password,
            'VerifyCode': verify_code
            }
    response = requests.post('https://www.qichamao.com/usercenter/dologin', headers=headers, data=data,
                             cookies=cookies)
    return response


def run_login(account, password):
    timestamp = str(int(time.time()))

    cookies = {
        # 'qznewsite.uid': uid,
        'Hm_lvt_55ad112b0079dd9ab00429af7113d5e3': timestamp,
        # 'ASP.NET_SessionId': 'nz4wcnaaazvciq4rik3ns5pr',
        'Hm_lpvt_55ad112b0079dd9ab00429af7113d5e3': timestamp,
    }
    uid = fetch_uid()
    cookies['qznewsite.uid'] = uid
    image_response = get_verify_code_image(cookies)
    verify_code = identify_verify_code(response=image_response)
    cookies['Hm_lpvt_55ad112b0079dd9ab00429af7113d5e3'] = str(int(time.time()))
    response = login(account=account, password=password, verify_code=verify_code, cookies=cookies)
    new_cookie = dict(response.cookies)
    cookies.update(new_cookie)
    return cookies


if __name__ == '__main__':
    account = '15916560656'
    password = '560656'
    assert account and password, '填入账号密码'
    cookies = run_login(account, password)
搜索次数达到值验证 verify_flow.py
import random
import time

import ddddocr
import execjs
import requests


def get_verify_code(cookies):
    headers = {
        'Connection': 'keep-alive',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/'
                      '97.0.4692.99 Safari/537.36',
        'sec-ch-ua-platform': '"Windows"',
        'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'no-cors',
        'Sec-Fetch-Dest': 'image',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }

    params = (
        ('t', '8405'),
    )

    response = requests.get('https://www.qichamao.com/usercenter/varifyImage', headers=headers, params=params,
                            cookies=cookies)

    return response


def identify_verify_code(response):
    ocr = ddddocr.DdddOcr()
    verify_code = ocr.classification(response.content)
    return verify_code


def get_js_verify_code(cookies):
    headers = {
        'Connection': 'keep-alive',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'Accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, '
                  '*/*; q=0.01',
        'X-Requested-With': 'XMLHttpRequest',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/'
                      '97.0.4692.99 Safari/537.36',
        'sec-ch-ua-platform': '"Windows"',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }

    timestamp = int(time.time() * 1000)
    params = (
        ('t', random.random()),
        ('_', timestamp),
    )

    response = requests.get('https://www.qichamao.com/home/GetJsVerfyCode', headers=headers, params=params,
                            cookies=cookies)

    return response.text


def get_mcfcode(cookies):
    uid = cookies.get('qznewsite.uid')
    js_code = get_js_verify_code(cookies)
    prefix = """
                    var window = {'document': {'cookie': 'qznewsite.uid=%s'}};
                    """ % (
        uid,)

    tail = """
                function getMfccode(){
                    return window.__qzmcf()
                }
                """
    js_code = prefix + js_code + tail

    ctx = execjs.compile(js_code)
    mfccode = ctx.call("getMfccode")
    return mfccode


def check_verify_code(verify_code, mcfcode, cookies):
    headers = {
        'Connection': 'keep-alive',
        'Content-Length': '0',
        'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
        'Accept': '*/*',
        'X-Requested-With': 'XMLHttpRequest',
        'sec-ch-ua-mobile': '?0',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                      'Chrome/97.0.4692.99 Safari/537.36',
        'sec-ch-ua-platform': '"Windows"',
        'Origin': 'https://www.qichamao.com',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
        'Accept-Language': 'zh-CN,zh;q=0.9',
    }

    params = (
        ('VerifyCode', verify_code),
        ('mcfCode', mcfcode),
    )

    response = requests.post('https://www.qichamao.com/usercenter/CheckVarifyImage', headers=headers, params=params,
                             cookies=cookies)
    return response


if __name__ == '__main__':
    # 需要验证的账号的cookie
    cookies = {
        'qznewsite.uid': 'pb5cafm0xvul512ohh1dp5oq',
        'Hm_lvt_55ad112b0079dd9ab00429af7113d5e3': '1646621806',
        'ASP.NET_SessionId': 'nz4wcnaaazvciq4rik3ns5pr',
        'qz.newsite': '4CD5BADE108CF94A34291C310DE303BFA89FECB45A6D77922B8CD251EF3A6E0629313313613DCB46086A9149989A4114C5B66C22A1232B3D79E7A280D021514F0623C8AC641967C0FDB0E4AEAEE87AC08AC25D880E7BA6F261EDB43CD0D4DA11D404E4D10FF0A9C2B371D2C61AEADA570F4CE3BC5B96B63E8FEB100BCE2986FB09C000EC5EA827EC9A4BF7281F78C6D5738C2509DCFE7085ABDB2951149797BAF36628BE152AF90E233213E45B84DA51FF0F99F06EBE1832D2988FE6E4B2BAE69E31D5A8',
        'Hm_lpvt_55ad112b0079dd9ab00429af7113d5e3': '1646632717',
    }
    image_response = get_verify_code(cookies)
    verify_code = identify_verify_code(response=image_response)

    mcfcode = get_mcfcode(cookies)

    # 验证验证码
    check_verify_code(verify_code, mcfcode=mcfcode, cookies=cookies)
posted @ 2022-09-03 15:27  愺様  阅读(156)  评论(0编辑  收藏  举报