爬虫逆向实战(十八)--某得科技登录

一、数据接口分析

主页地址:某得科技

1、抓包

通过抓包可以发现数据接口是AjaxLogin

2、判断是否有加密参数

  1. 请求参数是否加密?

    查看"载荷"模块可以发现有一个password加密参数和一个__RequestVerificationToken

  2. 请求头是否加密?

  3. 响应是否加密?

  4. cookie是否加密?

    查看cookie发现同样有一个__RequestVerificationToken,但是与表单参数中的不同

二、加密位置定位

1、password

观察表单中的加密参数password发现类似于base64转码,在控制台进行测试,发现确实就是

2、表单参数__RequestVerificationToken

通过搜索关键字可以发现,表单中的__RequestVerificationToken是取的html静态页面中的数值

3、cookie中的__RequestVerificationToken

清除cookie之后刷新页面,可以发现,是在请求静态页面时服务器设置的cookie

三、思路

首先请求html页面,获取到表单中的__RequestVerificationToken以及cookie,再根据获取到数据发送登录请求。

四、避坑

在发送请求时会遇到一个报错

在发送请求时加上一个verify=False的参数就可以了

源代码:

python 复制代码
"""
Email:912917367@qq.com
Date: 2023/8/16 16:38
"""
import base64
import re

import requests


class Spider:
    def __init__(self, username, password):

        self.session = requests.session()
        self.session.headers = {
            "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.7",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
            "Pragma": "no-cache",
            "Sec-Fetch-Dest": "document",
            "Sec-Fetch-Mode": "navigate",
            "Sec-Fetch-Site": "none",
            "Sec-Fetch-User": "?1",
            "Upgrade-Insecure-Requests": "1",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
            "sec-ch-ua": "^\\^Not/A)Brand^^;v=^\\^99^^, ^\\^Google",
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "^\\^Windows^^"
        }
        self.token = ''
        self.username = ''
        self.password = ''

    def get_token(self):
        url = "https://www.leadbank.com.cn/login/"
        # url = "https://www.baidu.com"
        response = self.session.get(url, verify=False)
        pattern = r'<input name="__RequestVerificationToken" type="hidden" value="(.*?)"'
        self.token = re.findall(pattern, response.text)[0]

    def login(self):
        encoded_bytes = base64.b64encode(self.password.encode('utf-8'))
        pwd = encoded_bytes.decode('utf-8')
        url = "https://www.leadbank.com.cn/customer/AjaxLogin"
        data = {
            "userName": self.username,
            "password": pwd,
            "mark": "encry",
            "rememberMe": "false",
            "returnUrl": "",
            "validcode": "n948",
            "random": "1692176276000",
            "__RequestVerificationToken": self.token
        }
        response = self.session.post(url, data=data, verify=False)

        print(response.text)
        print(response)


if __name__ == '__main__':
    s = Spider('账号', '密码')
    s.get_token()
    s.login()
相关推荐
WeeJot嵌入式1 天前
爬虫对抗:ZLibrary反爬机制实战分析
爬虫·python·网络安全·playwright·反爬机制
进击的雷神1 天前
攻克JSON嵌套HTML的双重解析难题:基于多层数据提取的精准爬虫设计
爬虫·html·json·spiderflow
前端小趴菜~时倾1 天前
自我提升-python爬虫学习:day05-函数与面向对象编程
爬虫·python·学习
进击的雷神1 天前
攻克JSON接口分页与对象数组处理:基于AJAX数据源的精准博客爬虫设计
爬虫·ajax·json·spiderflow
vx_biyesheji00012 天前
计算机毕业设计:Python汽车数据分析系统 Django框架 requests爬虫 可视化 车辆 数据分析 大数据 机器学习(建议收藏)✅
爬虫·python·算法·机器学习·django·汽车·课程设计
小白学大数据2 天前
效率翻倍:Scrapy-Redis 分布式全站爬虫并发优化进阶
redis·分布式·爬虫·scrapy
tang777892 天前
小红书平台用什么代理 IP 比较好?2026年3月实测数据 + 选型推荐
网络·爬虫·python·网络协议·tcp/ip·数据挖掘·ip
进击的雷神2 天前
突破POST分页与IP封锁:基于表单提交和代理转发的新闻爬虫设计
爬虫·网络协议·tcp/ip
小邓睡不饱耶2 天前
东方财富股吧话题爬虫实现:从接口请求到Excel数据落地
爬虫·excel
进击的雷神2 天前
攻克动态列表页结构:基于ID与URL双字段协同提取的精准爬虫设计
爬虫·spiderflow