python-3.x - 如何使用 WebSocket 发送消息?
问题描述
我在 DevTools 中打开了 Firefox 网络选项卡,我想通过 WhatsApp 发送一条消息,它使用 WebSockets 进行通信。这是发送消息时的样子:
现在,我想通过 Python 发送一个 Web Socket 消息,但我找不到方法。我用谷歌搜索了它,但找不到关于如何实现这一目标的适当解决方案。我不确切知道要提供哪些参数来发送消息。
到目前为止,这是我的代码:
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Sec-WebSocket-Version': '13',
'Origin': 'https://web.whatsapp.com',
'Sec-WebSocket-Extensions': 'permessage-deflate',
'Sec-WebSocket-Key': 'yVoOx/6Sn1wyiv9R3OopPQ==',
'Connection': 'keep-alive, Upgrade',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'Upgrade': 'websocket',
'TE': 'Trailers',
}
response = requests.get("http://wss://web.whatsapp.com/ws", headers=headers)
解决方案
推荐阅读
- android - 在 FlutterFlow 中创建唯一标识符的任何选项或建议?
- spring-boot - java中阿拉伯语内容的Base64解码问题
- html - a11y | Mac 画外音正在阅读 aria-label 和所有嵌套文本
- reporting-services - ssrs 中 Web 门户 url 和 Web 服务 url 之间的区别
- python - 启动时更改 webdrivers ip
- javascript - 如何在更改/键入/输入到 Javascript 函数时使用替换 jQuery 函数
- node.js - aws-amplify node.js 包是否支持相互 TLS API 连接?
- c# - 向文件名以数字结尾的文件添加缓存控制
- python - 如何更改我的 RL 模型的输出形状?
- asp.net - 为什么在 Asp.net Core MVC 的 bootstrap sticky 标头下渲染剃须刀页面