Anti-crawler method based on JS confusion
By dynamically encrypting key strings in the web page on the server side and generating JS obfuscated strings, combined with the use of decryption functions, it achieves high efficiency in resisting crawlers and normal user access, and solves the problem of anti-crawler methods in the existing technology that are harmful to users. Access inconvenience issues.
Patent Information
- Application Number
- CN202411615917.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-13
- Publication Date
- 2025-01-21
- Estimated Expiration
- Not applicable · inactive patent
Smart Images

Figure CN119341836A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of anti-crawler technology, and more specifically to an anti-crawler method based on JS obfuscation. Background Art
[0002] In the current Internet environment, the popularity and use of crawler programs have led to the illegal acquisition and abuse of a large amount of website data, posing a threat to the normal operation of the website and data security. Although traditional anti-crawler technologies such as IP blocking, verification code, and User-Agent detection can resist crawlers to a certain extent, they also bring inconvenience to normal users.
[0003] Therefore, how to develop an anti-crawler method that can both prevent crawlers and ensure efficient normal user access is an urgent problem that technicians in this field need to solve. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide an anti-crawler method based on JS obfuscation, which can both prevent crawlers and ensure efficient normal user access.
[0005] In order to achieve the above object, the present invention adopts the following technical solution:
[0006] An anti-crawler method based on JS obfuscation includes the following steps:
[0007] S1: The server obtains the string to be encrypted in the visited web page and dynamically generates an encryption key;
[0008] S2: The server encrypts the string to be encrypted using the encryption key to generate a JS obfuscated string;
[0009] S3: The server returns the webpage code including the JS obfuscated string and the decryption function to the access terminal;
[0010] S4: If the access end is a crawler user, the crawler user crawls the JS obfuscated string; if the access end is a normal access user, the normal access user calls the decryption function to decrypt the JS obfuscated string.
[0011] Preferably, S1 further includes: the character string to be encrypted is marked with a unique ID in the webpage, and the server side obtains the character string to be encrypted in the webpage based on the unique ID.
[0012] Preferably, S2 further includes: performing an XOR operation on the encryption key and the string to be encrypted to generate the JS obfuscated string.
[0013] Preferably, S3 further includes: the decryption function includes the encryption key.
[0014] It can be seen from the above technical solution that compared with the prior art, the present invention provides an anti-crawler method based on JS obfuscation. The present invention utilizes the characteristics that crawler users generally only obtain strings but do not decrypt encrypted strings, and the characteristics that normal access users automatically call the decryption function to decrypt encrypted strings. When the web page is accessed, the key string is dynamically encrypted, which can both prevent crawlers (that is, ensure the security of web page data) and ensure efficient access by normal users. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0016] Figure 1 The present invention provides an overall flow chart of an anti-crawler method based on JS obfuscation. DETAILED DESCRIPTION
[0017] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0018] like Figure 1 As shown, the embodiment of the present invention discloses an anti-crawler method based on JS obfuscation, comprising the following steps:
[0019] S1: The server obtains the string to be encrypted in the visited web page and dynamically generates an encryption key;
[0020] S2: The server encrypts the string to be encrypted using the encryption key to generate a JS obfuscated string;
[0021] S3: The server returns the webpage code including the JS obfuscated string and the decryption function to the access terminal;
[0022] S4: If the access end is a crawler user, the crawler user crawls the JS obfuscated string; if the access end is a normal access user, the normal access user calls the decryption function to decrypt the JS obfuscated string.
[0023] Furthermore, S1 further includes: the character string to be encrypted is marked with a unique ID in the webpage, and the server side obtains the character string to be encrypted in the webpage based on the unique ID.
[0024] Furthermore, S2 further includes: performing an XOR operation on the encryption key and the string to be encrypted to generate the JS obfuscated string.
[0025] For example: a web page has a key string (i.e., the string to be encrypted) "xxxxxxx". The key string is XORed bit by bit with the dynamically generated encryption key [118,39,73,238,91,62,32,53,142,128,153,52,148] to generate a JS obfuscated string [14,95,49,150,35,70,88].
[0026] Furthermore, S3 further includes: the decryption function includes the encryption key.
[0027] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0028] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. An anti-crawler method based on JS obfuscation, characterized in that: The following steps are involved: S1: The server obtains the string to be encrypted in the visited web page and dynamically generates an encryption key; S2: The server encrypts the string to be encrypted using the encryption key to generate a JS obfuscated string; S3: The server returns the webpage code including the JS obfuscated string and the decryption function to the access terminal; S4: If the access end is a crawler user, the crawler user crawls the JS obfuscated string; if the access end is a normal access user, the normal access user calls the decryption function to decrypt the JS obfuscated string.
2. According to the anti-crawler method based on JS obfuscation according to claim 1, it is characterized in that: S1 further includes: the character string to be encrypted is marked with a unique ID in the webpage, and the server side obtains the character string to be encrypted in the webpage based on the unique ID.
3. According to the anti-crawler method based on JS obfuscation according to claim 1, it is characterized in that: S2 further includes: performing an XOR operation on the encryption key and the string to be encrypted to generate the JS obfuscated string.
4. According to the anti-crawler method based on JS obfuscation according to claim 1, it is characterized in that: S3 further includes: the decryption function includes the encryption key.
Citation Information
Patent Citations
Data crawling method and device
CN111259224A
Anti-crawler method and system for protecting website resources based on encrypted confusion
CN116366231A
Anti-crawler method for web page text encryption
CN118018233A
Page data protection method and device, equipment and medium
CN118797582A
Data encryption processing method and apparatus, computer device, and storage medium
WO2022252632A1