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:有需要源码的私信我

相关推荐
Warson_L6 小时前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅6 小时前
海天线算法的前世今生
python·计算机视觉
韩师傅6 小时前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L6 小时前
LangGraph的MessageState and HumanMessage
python
韩师傅7 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L7 小时前
python的类&继承
python
Warson_L7 小时前
类型标注/type annotation
python
ThreeS10 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵11 小时前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏