The puppeter of nodejs realizes the code scanning login of JD automation function

Posted by laide234 on Thu, 10 Feb 2022 09:03:59 +0100

Recently, I want to realize a function of JD scanning code, logging in, automatic ordering and automatic rush purchase (ps: realize JD automation function),

!!! This project is purely for learning and commercial use is prohibited

Let me share with you how I can find the corresponding interface and parameters step by step by analyzing JD's website request and viewing the source code of JD's website

The crawler must be prepared with the basic header information of the interface. All interface requests below need to pass these parameters in the header to indicate that you are a normal user~

let header =  {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/531.36",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
        "Connection": "keep-alive"

I Code scanning login function

1. First open the JD home page website and press f12

Find the interface of QR code, get the request, and return a different QR code each time

Here you can guess the meaning of the parameter directly. appid: fixed 133, size: QR code, picture size, t: time stamp (not transmitted for personal testing)

2. Then it is found that the interface will be scanned regularly

After checking the return, it is used to monitor whether the QR code has been successfully scanned. The return format is jsonp, which is also a get request

The parameters appid (fixed 133), token (unknown), and_ (timestamp)

All the token s requested by the check interface here are the same, indicating that this is the unique id of the QR code, which is used to identify which QR code was successfully scanned to the back end

Let's copy the value of token 5ccgesxgs9dlbk7frzo45f2oxv6dwxn1 Press ctrl+f on the network to search where the value is obtained

Obviously, this is the set cookie field returned by the background on the interface that just obtained the QR code above, allowing the client to store the information on the cookie,

Then I made a direct request and found the error of the} parameter returned by the backend

Note: there must be some other parameters missing. After testing, I need to pass in the setCookie parameters of referer, Host and QR code interface on the header request header

All header information of the interface

let headers = {
    Host: '',
    Referer: '',
        'QRCodeKey=AAEAILN9uxDIBx5bK6UrmrnCKso0jcupIx2j03lvvlgF4ws9; HttpOnly;wlfstk_smdl=sqwlqhk3tweiw8tjjxpsqv244ug47gdz; PATH=/;',
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/531.36',
    Connection: 'keep-alive'

The interface returns that the QR code is not scanned. Please scan the QR code. The interface request is successful. The rest is to open JD app and scan the code to log in

After scanning the code to log in, it is found that the web page calls this interface

The value of the parameter t of the interface is monitored by the QR code above check Returned ticket field, returnUrl: callback address after successful login


The back end returns a large number of cookie s to the front end, and these user information after successful login should be saved


So far, JD's code scanning login function has been completed. After saving the login cookie, the subsequent shopping cart and order interface need to be passed in!!










Topics: Javascript node.js Front-end Back-end