python-websocket爬虫案例[Python基础]

内容摘要
一.今天做一个阿三的网站刚刚好是个websocket请求 精华都在这图上,和下面代码,没啥加密可以当个简单模板 目标网站url:https://m.jungleerummy.com/register 二.代码 impor
文章正文

一.今天做一个阿三的网站刚刚好是个websocket请求

精华都在这图上,和下面代码,没啥加密可以当个简单模板
目标网站url:https://m.jungleerummy.com/register

二.代码

import websocket
import json
url = "wss://www.jungleerummy.com/ws"
headers= {
    "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1"
}
ws = websocket.create_connection(url=url,headers=headers, timeout=15)
print(ws.recv())
phone = 7406555536
data = {"type":"cm-registration-request","network":"JUNGLEERUMMY","username":"","password":"","email":phone,"userDeviceType":"mob","extra":{"adkey":"junglee","deviceInfo":{"deviceType":"mob"},"utmParams":{"utm_source":"","utm_medium":"","utm_campaign":"","utm_term":"","utm_content":"","gclid":"","fbclid":"","fbp":"","fbc":""},"referralId":0,"browserName":"Safari","browserVersion":"10","userAgentType":"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1","userAgent":"Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1","otpTracking":{"pageUrl":"REGISTRATION","activity":"SIGNUP","otpMobileNo":"","resend":0,"mobile_number_detection_permission":"NO","mobile_number_capturing":"MANUAL","otp_capturing_permission":"NO","otp_capturing":"MANUAL"},"pageName":"/register","mobileNumber":phone,"registerWith":"MOBILEOTP"},"isBot":False}
ws.send(json.dumps(data))  # 以字符串发送消息
print(ws.recv())
ws.close()  # 关闭连接

三.补充知识点

ws.send_frame("以帧形式发送数据")   # 以帧形式发送数据
ws.recv_data_frame()    # 接收以帧发送的数据
ws.send_binary("以二进制格式发送数据".encode())   # 以二进制格式发送数据
代码注释
[!--zhushi--]

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!