Master jsrpc: From Browser Hook to Automated Data Extraction
This step‑by‑step guide shows how to hook cookies in the browser, locate and export the encrypted jsrpc function, start a local ws service, register actions, and use Python requests to automate data retrieval from a target site.
Overview
This article provides a practical tutorial on using jsrpc for web‑scraping, covering browser hooking, function extraction, local service setup, action registration, and automated data fetching with Python.
1. Hook the Cookie
In the browser console execute:
Object.defineProperty(document, "cookie", {set:function(a){debugger}})2. Open Debug Mode
Navigate to the next page and enable the debugger.
3. Locate the Encryption Function
In the Call Stack panel, expand entries until you find the encrypted function; its values correspond to the request parameters.
4. Export the Function
Run the following in the console (note the omission of parentheses): window.dcpeng = ct.update Note: Using ct.update() would assign the result instead of the function.
5. Close Debug Mode
Close the debugger to allow WebSocket injection.
6. Start the Local Service
Double‑click the compiled binary: win64-localhost.exe This launches the jsrpc server.
7. Inject jsrpc Client Code
Copy the entire content of JsEnv.js and paste it into the browser console (breakpoints may need to be disabled).
8. Connect to the Service
var demo = new Hlclient("ws://127.0.0.1:12080/ws?group=v&name=test");9. Register an Action
// Register a method named "get_v"
// The second argument is a function; resolve receives the value to send to the server.
// The third argument (param) is optional.
demo.regAction("get_v", function(resolve, param) {
// var c = "好困啊" + param;
var c = dcpeng();
resolve(c);
});10. Retrieve Data via HTTP
Open the following URL in a browser (replace group and name with the values used during injection):
http://127.0.0.1:12080/go?group=v&name=test&action=get_v11. Automate Requests with Python
Use the requests library to fetch the value of get_v and then send further requests.
import requests
v_url = "http://127.0.0.1:12080/go?group=v&name=test&action=get_v"
v_res = requests.get(url=v_url).json()["get_v"]
cookies = {
'session': '6c78df1c-37aa-4574-bb50-99784ffb3697.Qcl0XN6livMeZ-7tbiNe-Ogn8L4',
'v': v_res,
}
headers = {
'Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'hexin-v': 'A3_4zkkuI7xygCZatjHGiHM8DlgKZNPp7bnX-hFMGsZ175EOGTRjVv2IZ04i',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36 Edg/97.0.1072.69',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'http://spider.wangluozhe.com',
'Referer': 'http://spider.wangluozhe.com/challenge/6',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
}
data = {
'page': '3',
'count': '10',
}
response = requests.post('http://spider.wangluozhe.com/challenge/api/6', headers=headers, cookies=cookies, data=data, verify=False).json()
print(response)The printed result matches the data shown on the web page.
12. Scale to Full Site
Wrap the request in a loop over page ranges to crawl the entire site.
Conclusion
The jsrpc tool enables rapid, black‑box data extraction without manual environment setup, making web‑scraping more efficient.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
