Record the various pits encountered on the crawler road 01

Record the various pits encountered on the crawler road 01

2020.01.12 ---- jsonp

What should I do if the func ('encrypted data') returned by Ajax cannot find the decryption function?

What is jsonp

To quote the original "Rookie Tutorial":

Jsonp (JSON with Padding) is a "use mode" of json, which allows web pages to obtain information from other domain names (websites), that is, to read data across domains.
Why do we need a special technology (JSONP) to access data from different domains (websites)? This is because of the same-origin strategy.
The same-origin policy, which is a well-known security strategy proposed by Netscape, is now used by all browsers that support JavaScript.

As for why jsonp is used, it is not the subject, skip it.

Give a chestnut

Here is an example of Qunar hotel reviews .
Open the link, enter the debug panel, refresh the page, search for comment data, and find that there is no corresponding result.
Where is the data? After step-by-step debugging, it is found that the data is generated by a request result of 1? Qan = xxx, where 1 is the number of comment pages.
Insert picture description here
This response parameter is the data we want. It is composed of a function name and function parameters. The first parameter is the ciphertext of the data we need. How to quickly find the location of this decryption method?

How to solve this kind of problem

First find the corresponding js, enter js and hit a breakpoint.

Insert picture description here
After formatting a breakpoint, click the next page to enter the breakpoint.

There is a small pit here. The breakpoint position cannot be hit casually. It is possible that the breakpoint cannot be entered, or that the request has not been issued after the breakpoint has been entered, or the return result has not been obtained yet. Since it is not an ajax request, the xhr breakpoint is useless. The dom breakpoint may be ok, didn't try.

tips: Enter the jquery file, find the callback function after sending the request successfully, and then put a breakpoint on the first line of the callback function.
Insert picture description here
Insert picture description here

Note here that, because the success callback function of the send request is marked with a breakpoint, each successful ajax request will enter a breakpoint. When debugging, it depends on whether the relevant request appears in the network panel.
When the 2? Qan = xxx request appears, copy the function name in the response to the console panel and press Enter.

Insert picture description here
Double-click the function to enter the source panel, this is the decryption function we want.
Insert picture description here

to sum up

jsonp encountered more or put the data on the web page for typesetting, and this kind of decryption encountered less.

Published 8 original articles · Liked5 · Visits1874

Guess you like

Origin blog.csdn.net/weixin_42525191/article/details/103947908