python-websocket爬蟲案例

一.今天作一個阿三的網站剛恰好是個websocket請求

精華都在這圖上,和下面代碼,沒啥加密能夠當個簡單模板
目標網站url:https://m.jungleerummy.com/register
python

二.代碼

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())   # 以二進制格式發送數據

本文分享 CNBlog - 加載時間中.....。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。web

相關文章
相關標籤/搜索