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

相关推荐
用户83562907805125 分钟前
Python 设置 Excel 条件格式教程
后端·python·excel
2401_874732531 小时前
Python上下文管理器(with语句)的原理与实践
jvm·数据库·python
l1t1 小时前
与系统库同名python脚本文件引起的奇怪错误及其解决
开发语言·数据库·python
Jackey_Song_Odd1 小时前
Part 1:Python语言核心 - 内建数据类型
开发语言·python
带娃的IT创业者1 小时前
WeClaw WebSocket 连接中断诊断:从频繁掉线到稳定长连的优化之路
python·websocket·网络协议·php·fastapi·实时通信
GinoWi1 小时前
Chapter 4 Python中的循环语句和条件语句
python
GinoWi2 小时前
Chapter 5 Python中的元组
python
前进的李工2 小时前
LangChain使用之Model IO(提示词模版之PromptTemplate)
开发语言·人工智能·python·langchain
Storynone2 小时前
【Day27】LeetCode:56. 合并区间,738. 单调递增的数字
python·算法·leetcode
叶子2024222 小时前
承认错误才能成长
python