Python websocket crawler case

Time:2021-12-4

1、 Today, it’s just a websocket request to do a San’s website

The essence is in this picture, and the following code, no encryption can be a simple template.
Target site URL: https://m.jungleerummy.com/register

2、 Code

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)) # sends the message as a string
print(ws.recv())
WS. Close() # close connection

3、 Supplementary knowledge points

ws.send_ Frame ("send data as frame") # send data as frame
ws.recv_ data_ Frame() # receives data sent in frames
ws.send_ Binary ("send data in binary format". Encode()) # sends data in binary format

Recommended Today

Hive built-in function summary

1. Related help operation functions View built-in functions: Show functions; Display function details: desc function ABS; Display function extension information: desc function extended concat; 2. Learn the ultimate mental method of built-in function Step 1: carefully read all the functions of the show functions command to establish an overall understanding and impression Step 2: use […]