web爬虫 - 实例一(猿人学17题)

这个案例很简单, 不多说了

import httpx

def get_info(ind):
    url = "https://match.yuanrenxue.cn/api/match/17?page=" + str(ind)
    headers = {
        'authority': 'match.yuanrenxue.com',
        'cookie': 'Hm_lvt_c99546cf032aaa5a679230de9a95c7db=1690184377,1690941596,1690969392,1690971468; Hm_lvt_9bcbda9cbf86757998a2339a0437208e=1690184376,1690941595,1690969392,1690971468; Hm_lvt_434c501fe98c1a8ec74b813751d4e3e3=1690971476; Hm_lpvt_434c501fe98c1a8ec74b813751d4e3e3=1690971476; tk=-7962460354862954537; sessionid=1mcld1cz4z54nrnhkuxfq7wtysc7vdds; Hm_lpvt_9bcbda9cbf86757998a2339a0437208e=1691027865; Hm_lpvt_c99546cf032aaa5a679230de9a95c7db=1691027869',
            'referer': 'https://match.yuanrenxue.com/match/3',
        'user-agent': 'yuanrenxue.project',
    }

    client = httpx.Client(http2=True)
    resp = client.get(url=url, headers=headers)
    res_json = resp.json()

    sum = 0
    for val_dict in res_json['data']:
        sum += val_dict['value']
    return sum


if __name__ == '__main__':
    sum_num = 0
    for i in range(1, 6):
        res = get_info(i)
        sum_num += int(res)
    print(sum_num)

你可能感兴趣的:(前端,爬虫,数据库)