猿人学刷题系列(第一届比赛)——第四题

题目:采集这5页的全部数字,计算加和并提交结果

猿人学刷题系列(第一届比赛)——第四题_第1张图片

地址:https://match.yuanrenxue.cn/match/4

页面分析

首先打开开发者工具然后刷新界面进行抓包。

猿人学刷题系列(第一届比赛)——第四题_第2张图片

通过返回的数据来看,我们需要的数据极有可能是位于info键对应的值中,由于其是html标签,所以我们可以先将info对应的值写到本地html文本之中。

猿人学刷题系列(第一届比赛)——第四题_第3张图片

通过右侧html中的代码不难看出,返回的数据是以图片的形式进行返回的,那么也就是说我们是没有办法直接获取到对应的数字数据的。所以这里可以提供两种方案,一是通过识别算法对图片中对应的数字进行识别,二是手动构建映射关系,此处数字是比较少的,所以选择构建映射关系更加方便。映射关系的构建根据每一个标签对应的数字即可构建,如下图:

猿人学刷题系列(第一届比赛)——第四题_第4张图片

Current source作为键然后6作为值构建映射关系,其他数字同理。映射关系如下:

number_base = {
    'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAdCAYAAACqhkzFAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAMTSURBVEhLrZY/TBNRHMe/bY82LeGA0Dp4NTGYqO1gdKEMwmQcGh38M5CQlGDSwWiMAwwYg2iCJsZJQ9CJ0ETsQMJgwuagLIUFXIAFXNoYcqDloLRXrq3v7v3aXktbSPCTXO77fZRvf/feu9+r5dz5iwX8R+oESigMPka6/wb2vSJUBx+1QoVD3kTz7DScb+f4YBVHA6U+ZKLPsON1IE9DtbDLP9AxEIawRgOEle4cKYSD+ZeQq8IcKquMXTbyOllPL7aiEWgSDRCmQAnahyHsiGQZruUvkIKXcObyFeM62zcOd1ylvwJ5MYDkuxA5Tjlw8A2S12iyGM7YODrujsFqfqTFCJw9L+CWyTPS3QPIBMgwKFBC9n4AaW4AdQVtQxEy1czBObkIJznAi9TDO6SLgVIYqt9QBq5YFEKCTC2momg2VXngD5bmnAc+uIqUIXQUOL/X3hJl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azCNuUiY4E67cXSLvtJq1hojdhx57nPX4fMDOxL3OSMiihwmHzchu8njrSGmGGclc/Vit5BEibxEXw7bdgzy9BZqEyziLP5UH6Cn2AsV3ZBF+DnVTYlBuxNe/CGqcpSHPIdl6DeY60EXsdfCNtWLVp0rQyhhOORrU6vcKOamyEzNgUU4fuRTdTWHIj6fUkLCSDfCl2GrR433CvuAB+ipXqLM8iVzCMd29gFSiGDb4rWi/J0IE9fr88QFhEAoWHMwWzIFLMeplbAaV3ZFiIIPXjb4gXvBQx+Ax1MfUeGuEM1cYKZzMauhFv2Arg2X6k8CgCuRkUKaQgWGOo0CwYHLlS+LocJA7B3oKdMmOfOMi8wdDUy84nxQrrtU8h1egbNpyLkAbr9T1rQO/h5EtYJ0Q9wRVguXsYG30tCFwq1HJ2B4KtPdiY6cfyac3NrD4VJMQpk1ROij7uyJk/dmTIcgxjXT7+aUK27OsFOZN56BWqjIOrf4isWRHxlImOiLSh+0iaJqnCKmTPA4aMpREkVpcjx/UWGdOLSBZDNw0booC0iY/IuVoO6+NxoJjXbyVRK+LwCzYGAp7v+FWprbR5dhDZ1Z1RKowZB/y5+rbhhK/qO2bD/FMncb7kHClGRT07vxRDgGVgSo1iNrTZUnChrIQUm26zA5sUm4QZcJNa/G89bHDD+6SCFkRCem8Vkp9r1114hfbDToaBmlcQH4TMgMSFL0giM4Vww2Z2AqaGsd3qpIQB5We1bxTe7mqsh46ctIjU9kfq/gsRPuWuUfy8XkCCrRzbexTBz0yCpBRMzCzDdRfcgd/mIxdFYveiNsLNOGEMWc6qCDOFA4vCbu7WJmzXOrDF21SjEBz7x2Bm/xisQ90wf5inbCT/dVIiAf4ApbEnkB6qHqsAAAAASUVORK5CYII=': 9
} # 构建数字映射字典

映射字典构建好之后是不是就可以去进行解析然后映射出对应的数字了呢?当然不行的,我们将html文本往下翻,会发现有的td标签中出现了4个以上的img标签,但是很明显我们的数据最大就是4位数,也就是说最多也就是4个img标签,那多的这些标签是什么情况呢?来通过页面中已经渲染好的html来看。

猿人学刷题系列(第一届比赛)——第四题_第5张图片

通过这里来看的话就会发现部分img标签的style属性中存在display值,如果去掉这些值的话那么剩下的img刚好数量就能够对应了,那么也就是说存在着display值的标签是不显示的

猿人学刷题系列(第一届比赛)——第四题_第6张图片

所以我们只需要将这个display对应的标签删除之后剩下的就是我们需要的数字了。但问题是,响应数据中并没有看到与display相关的任何内容,但是在响应数据中多了一个class属性

猿人学刷题系列(第一届比赛)——第四题_第7张图片

这个很明显能够看得出来是md5加密,但问题就是谁来加密的问题,所以我们可以去跟栈查看一下,回到network中。

猿人学刷题系列(第一届比赛)——第四题_第8张图片

跟进去后直接就能看到如下图的逻辑

猿人学刷题系列(第一届比赛)——第四题_第9张图片

那这就明显了,就是说以j_key为准设置标签的display格式,而j_key的生成逻辑为

j_key = ‘.’ + hex_md5(btoa(data.key + data.value).replace(/=/g, ‘’));

其中第一个加号左边的.是在css的后代选择器符号,所以在实际计算的时候我们是不需要的,因此将这个算法改写为python后为:

from hashlib import md5
from base64 import b64encode

j_key = md5(b64encode((key + value).encode()).decode().replace('=', '').encode()).hexdigest()

猿人学刷题系列(第一届比赛)——第四题_第10张图片

刚好,能够和写入本地中的值相对应,那么也就是说只要这个值相等的话意味着这个img标签是不被显示的,也就是需要我们删除的。那么我们来验证一下是否如我们推导所示呢。这里要判断的话我们可以在生成的j_key前面拼接上img_number ,然后由于其是html页面,所以可以通过xpath来解析出img中的class值。

猿人学刷题系列(第一届比赛)——第四题_第11张图片

可以看到输出了每一页的img标签的数量,从前三页来看是能够对应的。

猿人学刷题系列(第一届比赛)——第四题_第12张图片

第一页共39个数字,也就是由39个img标签来组成。所以思路推导正确。但是还有个问题,那就是位置顺序问题,回到浏览器中。

猿人学刷题系列(第一届比赛)——第四题_第13张图片

如上图所示,数字8应该是位于十位上,那么就应该是第三个img标签但实际上其是位于第二个img标签,所以如果我们直接将返回的图片直接映射数字的话肯定就是错误的,一定是先将其还原到正确的位置才能进行映射。那应该怎么还原呢?可以看到,在img标签中有一个style属性,其值如:"left:0px"这样的格式,所以我们就通过第一页的第一个数字来看。

6在第一位,其left对应的值为0px

猿人学刷题系列(第一届比赛)——第四题_第14张图片

第二个数字0对应为-11.5px

猿人学刷题系列(第一届比赛)——第四题_第15张图片

第三个数字8,对应为11.5px

猿人学刷题系列(第一届比赛)——第四题_第16张图片

最后一个为1,对应为0.0px

猿人学刷题系列(第一届比赛)——第四题_第17张图片

综上来看的话,当left: 0.0px时,数字的位置是不需要移动的;当left: 11.5px时,表示数字的位置向右移动1位,如上图中的8,位于第二个img,所以要移动到第三个img才是正确的位置;当left: -11.5px时,表示数字要向左移动1位,如上图中的0,需要向左移动一位才是正确位置。再来看其他数字,如下图

猿人学刷题系列(第一届比赛)——第四题_第18张图片

如此处的数字3,style中值为left:23.0px刚好是11.5的两倍,那么也就意味着3需要向右移动两位才是准确的位置。以此来看的话,假如我们将这些img标签放在列表中(以第一个数字6081为例),那么从响应的数据来看的话其在列表中对应的位置为[6,8,0,1],对应的索引值(处理前的索引值)为0,1,2,3,要将其进行还原那么可列出公式,设基数为base_px = 11.5,每一个数字对应的img标签中style取出的left值为x,那么最终每一个数字对应的准确的索引值index就等于x/base_px+处理前的索引值,对应的Python代码如下:

index = int(x/base_px)+base_index

那么实现代码的时候我们只需要将原本的img标签依次添加到一个列表中,然后对应去修改一个列表的元素值就可以啦。完整代码如下:

import base64
import hashlib
import requests
import re
from lxml import etree

number_base = {
    'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAdCAYAAACqhkzFAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAMTSURBVEhLrZY/TBNRHMe/bY82LeGA0Dp4NTGYqO1gdKEMwmQcGh38M5CQlGDSwWiMAwwYg2iCJsZJQ9CJ0ETsQMJgwuagLIUFXIAFXNoYcqDloLRXrq3v7v3aXktbSPCTXO77fZRvf/feu9+r5dz5iwX8R+oESigMPka6/wb2vSJUBx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exTBz0yCpBRMzCzDdRfcgd/mIxdFYveiNsLNOGEMWc6qCDOFA4vCbu7WJmzXOrDF21SjEBz7x2Bm/xisQ90wf5inbCT/dVIiAf4ApbEnkB6qHqsAAAAASUVORK5CYII=': 9
} # 构建数字映射字典
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
    'Cookie': 'sessionid=835l5naphxo5zdty23bfz3v0ofzymdto;'
}
url = 'https://match.yuanrenxue.cn/api/match/4?page=%s'
base_px = 11.5   # 基本单位
result_sum = []     # 保存最终数据


def jiami(key, value):
    """加密处理函数"""
    result = base64.b64encode((key + value).encode()).decode().replace('=', '').encode()
    result = hashlib.md5(result).hexdigest()
    return result


for i in range(1, 6):
    response = requests.get(url % i, headers=headers).json()
    key, value = response['key'], response['value']
    img_number = "img_number " + jiami(key, value)
    info = response.get('info')
    # with open('1.html', 'w', encoding='utf-8') as f:
    #     f.write(info)
    tree = etree.HTML(info)
    td_lst = tree.xpath('//td')
    for td in td_lst:
        # xpath解析出所有img标签并筛选掉不显示的img标签
        number_lst = [i for i in td.xpath('.//img') if i.xpath('./@class')[0] != img_number]
        t = [0 for i in number_lst]
        base_index = 0
        for n in number_lst:
            x = float(re.findall('left:(.*?)px', n.xpath('./@style')[0])[0])
            num = number_base[n.xpath('./@src')[0]]
            index = int(x / base_px) + base_index   # 需要移动的位数为int(px / basic_multiple),那么还原后的索引就应该加上本身的索引
            base_index += 1
            t[index] = str(num)
        result_sum.append(int(''.join(t)))

print(sum(result_sum))	# 最终结果为243701

猿人学刷题系列(第一届比赛)——第四题_第19张图片

你可能感兴趣的:(猿人学竞赛题,数据库,python)