python爬虫登录到海康相机管理页面

简述

1.最近接到个任务是在管理页面更改相机的某个参数,下载官方的sdk貌似没有提供这个接口,所以只能自己写爬虫登录发请求了。

1.主要步骤

1.1 发送get请求获取到salt,sessionID,challenge等信息

http://admin:123456@192.168.1.80/ISAPI/Security/sessionLogin/capabilities?username=admin

1.2 再次发送这个请求,这次要带上一个随机数random。random生成规则如下:

timestamp = str(int(time.time()))

md5_hash = hashlib.md5(timestamp.encode()).hexdigest()

md5_substring = md5_hash[:8].replace("#", "")

result = str(int(md5_substring, 16))[:8]

url += "&random=" + result

print(url)

1.3 最后拿到第二次获得到salt,sessionId,challenge信息和加密的登录密码登录

http://192.168.1.80/ISAPI/Security/sessionLogin?timeStamp=

1.4 问题注意

复制代码
有个特别恶心的问题是requests的post库会转义尖括号。

使用来去除

unescaped_string = urllib.parse.unquote(validation)

最后成功的登录截图:

ps:有需要源码的私信我

相关推荐
阿尔的代码屋19 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者2 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者2 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh2 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅2 天前
Python函数入门详解(定义+调用+参数)
python
曲幽2 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
两万五千个小时2 天前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
哈里谢顿2 天前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
用户8356290780512 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng83 天前
Python+Django+H5+MySQL项目搭建
python·django