简体   繁体   English

使用 Python 或 JavaScript 获取 websocket 与 WhatsApp 的连接?

[英]Get websocket connection to WhatsApp using Python or JavaScript?

I copy the websocket request from the chrome network tab and try to use it as fetch and clearly is not working because fetch only support HTTP(S) .我从 chrome 网络选项卡复制了 websocket 请求并尝试将其用作 fetch 并且显然不起作用,因为 fetch 仅支持HTTP(S)

Is there a way I can connect to WhatsApp websocket connection by either Python or JavaScript ?有没有办法可以通过PythonJavaScript连接到 WhatsApp websocket 连接?

I don't know If this will help, you can always use WebSocket in node.js.我不知道这是否有帮助,您始终可以在 node.js 中使用 WebSocket。 Similarly, socketio module is available in python.同样, socketio模块在 python 中可用。

I tried this in my local machine but the socket server throwed an unexpected Forbiden 403 error.我在我的本地机器上尝试了这个,但是套接字服务器抛出了一个意外的 Forbiden 403 错误。

Anyway, this is the example:无论如何,这是一个例子:

const WebSocket = require('ws')
var socket = new WebSocket("wss://web.whatsapp.com/ws")

socket.onopen = (e)=>console.log("connected")

socket.onmessage = (e)=>console.log("msg",e)

socket.onerror = (e)=>console.log("error",e)

WebSocket Github repo link WebSocket Github 回购链接

You need to use the flask-socketio and for javascript socket library.您需要使用 flask-socketio 和 javascript 套接字库。 The steps are to connect and then send data to the function mentioned.步骤是连接然后发送数据到提到的function。 You need to read the documentation as it is pretty simple.您需要阅读文档,因为它非常简单。

You can get connect to socket in chrome using您可以使用 chrome 连接到套接字

let socket = new WebSocket("wss://web.whatsapp.com/ws");


socket.onopen = (e)=>console.log("connected")

socket.onmessage = (e)=>console.log("msg",e)

socket.onerror = (e)=>console.log("error",e)

but you can't listern messages.但你不能收听消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM