Anti-crawler method and system based on canvas drawing text, storage medium and equipment
By drawing divided text fragments in the canvas and combining them with the arrangement of unextracted fragments, combined with encryption technology, it solves the problem that the existing text obfuscation method is easy to be cracked, improves the security of the data and the difficulty of anti-crawling, and provides a new anti-crawling method. crawler solution.
Patent Information
- Application Number
- CN202411254207.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-10-11
AI Technical Summary
Existing text obfuscation methods are easily cracked, leading to data leaks and economic losses. Existing anti-crawler technologies are commonly parsed in business scenarios and have a large number of cracking solutions.
By dividing the data to be kept confidential into a collection of data fragments according to certain rules, and drawing some fragments on the canvas, and arranging the unextracted fragments on the page to increase the difficulty of crawling, the national secret SM3 and SM4 are used for encryption to ensure the security of the data. Security.
It improves data security, increases crawling difficulty, provides new anti-crawler ideas, reduces development costs and code complexity, and ensures data protection.
Smart Images

Figure CN118760798A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of crawler technology, and in particular to an anti-crawler method, system, storage medium and device based on canvas drawing text. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] Common crawler technologies are mainly divided into two types. One is to obtain data through scripts or program access interfaces, which can usually be effectively dealt with by using data encryption transmission; the other is to obtain data after parsing the web page source code through scripts or programs. For this, anti-crawler technology such as text obfuscation has been derived.
[0004] The commonly used text obfuscation methods currently include: 1. Image camouflage, which is to disguise sensitive information such as price, quantity, and mobile phone number through images; 2. CSS offset, which is to shuffle the displayed content and then use CSS to rearrange the disordered text to a normal readable order; 3. SVG graphic mapping, which is to display sensitive information through SVG; 4. Data interference, which is to randomly mix interference data in the displayed content and then hide the interference data through CSS; 5. Custom font files. However, the disadvantage of the above methods is that they are easy to crack as long as you master a certain pattern. Summary of the invention
[0005] In order to solve the technical problems existing in the above-mentioned background technology, the present invention provides an anti-crawler method, system, storage medium and device based on canvas drawing text. The present invention extracts some fragments from a set of segmented text fragments according to certain rules and draws them on the canvas, and then combines them with the remaining fragments, so as to protect the text data and avoid economic losses caused by large-scale data leakage.
[0006] In order to achieve the above object, the present invention adopts the following technical solution: A first aspect of the present invention provides an anti-crawler method based on drawing text on a canvas.
[0007] An anti-crawler method based on canvas drawing text, comprising: Acquire the data to be kept confidential, segment the data to be kept confidential according to the set rules, and obtain a set of data segments and position arrangement information of the data segments; Traversing the data fragment set, extracting some data fragments from the data fragment set according to a set rule, creating canvases for the extracted some data fragments, and obtaining a first canvas set; Based on the position arrangement information of the data fragments, the data fragments at the corresponding positions of each canvas in the canvas set are drawn into the corresponding canvas to obtain a second canvas set; The unextracted data segments and the second canvas set are arranged in the page according to the position arrangement information of the data segments.
[0008] Furthermore, the data to be kept confidential are segmented according to a set rule, and the method includes: if the length of the data to be kept confidential is less than a set threshold, the data to be kept confidential are segmented according to one character corresponding to one data segment.
[0009] Furthermore, the data to be kept confidential are segmented according to a set rule, and the method further includes: if the length of the data to be kept confidential is greater than or equal to a set threshold, the data to be kept confidential are segmented according to at least two characters corresponding to one data segment.
[0010] Furthermore, a part of the data segments are extracted from the data segment set according to a set rule, and the method includes: extracting the data segments of odd bits in the data segment set.
[0011] Furthermore, some data segments are extracted from the data segment set according to a set rule, and the method further includes: extracting even-numbered data segments from the data segment set.
[0012] Furthermore, some data segments are extracted from the data segment set according to the set rules, and the method further includes: setting data segments at each interval and extracting at least one data segment from the data segment set.
[0013] Furthermore, the method for obtaining the data to be kept confidential includes: obtaining the data to be kept confidential that has been encrypted by the national encryption SM4 through the content information acquisition interface.
[0014] A second aspect of the present invention provides an anti-crawler system based on canvas-based text drawing.
[0015] An anti-crawler system based on canvas text drawing, comprising: A segmentation module is configured to: obtain the data to be kept confidential, segment the data to be kept confidential according to a set rule, and obtain a set of data segments and position arrangement information of the data segments; A canvas creation module is configured to: traverse the data segment set, extract some data segments from the data segment set according to a set rule, create canvases for the extracted some data segments, and obtain a first canvas set; A canvas drawing module is configured to: based on the position arrangement information of the data fragments, draw the data fragments at the corresponding position of each canvas in the canvas set into the corresponding canvas to obtain a second canvas set; The page arrangement module is configured to: arrange the unextracted data segments and the second canvas set in the page according to the position arrangement information of the data segments.
[0016] A third aspect of the present invention provides a computer-readable storage medium.
[0017] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the anti-crawler method based on canvas drawing text as described in the first aspect above.
[0018] A fourth aspect of the present invention provides a computer device.
[0019] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the anti-crawler method based on drawing text on a canvas as described in the first aspect above are implemented.
[0020] Compared with the prior art, the present invention has the following beneficial effects: In view of the technical problem that several text obfuscation methods in the background technology are easy to crack if specific rules are mastered, and then the data is crawled; the present invention divides the text to be encrypted into a set according to certain rules, extracts some fragments according to certain rules and draws them on the canvas respectively, and then replaces the text at the corresponding position with the corresponding canvas, and displays them on the page in combination. The crawler needs to crawl by category and then combine them, which increases the difficulty of crawling and protects the data displayed on the page.
[0021] The existing anti-crawler technology is widely used in business scenarios and has been analyzed by crawler technicians. There are also a large number of technical problems such as cracking solutions. The present invention divides the text to be encrypted into a set, extracts some fragments from them and draws them on the canvas, and then combines them with the remaining fragments to display on the page. The text and the canvas are mixed and displayed, which increases the difficulty of anti-crawling and protects the security of data to a certain extent. It provides new ideas for the current anti-crawling technology.
[0022] The present invention uses national encryption SM3 and national encryption SM4 to authenticate and encrypt data packets respectively, and adopts canvas to draw text. The data is invisible in the source code, and the readability of the divided text segments is reduced. Under multiple protections, the security of the data is guaranteed. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0024] Figure 1It is a flow chart of the anti-crawler method based on canvas drawing text shown in the present invention; Figure 2 This is a diagram showing an example of segmentation according to the present invention. DETAILED DESCRIPTION
[0025] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0026] It should be noted that the following detailed descriptions are all illustrative and intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0027] Embodiment 1 like Figure 1 As shown, this embodiment provides an anti-crawler method based on drawing text on a canvas. This embodiment uses the method applied to a server as an example. It can be understood that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network servers, cloud communications, middleware services, domain name services, security services CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this application. In this embodiment, the method includes the following steps: Acquire the data to be kept confidential, segment the data to be kept confidential according to the set rules, and obtain a set of data segments and position arrangement information of the data segments; Traversing the data fragment set, extracting some data fragments from the data fragment set according to a set rule, creating canvases for the extracted some data fragments, and obtaining a first canvas set; Based on the position arrangement information of the data fragments, the data fragments at the corresponding positions of each canvas in the canvas set are drawn into the corresponding canvas to obtain a second canvas set; The unextracted data segments and the second canvas set are arranged in the page according to the position arrangement information of the data segments.
[0028] The goal of the present invention is to draw the data that needs to be kept confidential on the canvas, first slice the data according to certain rules, then get a set of data fragments, extract some data fragments according to certain rules, create canvases for these data fragments respectively and draw the data on the canvas, then replace the corresponding canvases according to the position of the data fragments in the set, and finally splice the set containing the data fragments and canvases and display them on the page. This way of mixed display of data and canvas requires crawlers to crawl and merge them by categories, which greatly increases the difficulty of crawling and protects the security of data to a certain extent.
[0029] The present embodiment is described in detail below: Define the server authentication identity information interface and content information acquisition interface. After the user enters the plain text password, the value generated by the national encryption SM3 is compared with the password value calculated by SM3 and stored in the database to verify the user's identity information. Configure the content information acquisition interface to return the data packet that needs to be displayed on the web page. During the transmission process, the configuration data packet is encrypted by the national encryption SM4.
[0030] After logging in, the client calls the content information acquisition interface. First, the data is sliced according to certain rules. Usually, short character data such as time, amount, quantity, etc. are segmented into 1 character segment. Other long texts, such as introduction and description, can be segmented into 2-5 characters. The segmentation length can also be customized according to the length of the text. After the text is segmented, a set is obtained. For example, 2024-05-05 is segmented into list = ['2', '0', '2', '4', '-', '0', '5', '-', '0', '5'].
[0031] The canvas tag is an element of HTML, namely the canvas tag. Graphics can only be drawn through the API it provides. It captures mouse events, and any mouse events will not be propagated to the elements under it, so the mouse cannot select the drawn content. If you need to interact with the content under it, you need to listen to the mouse events of the canvas to achieve it; it allows images and graphics to be drawn dynamically in the browser. All drawing operations are performed through JavaScript at runtime and will not be directly reflected in the HTML source code.
[0032] By using HTML to traverse the collection, you can extract some fragments according to certain rules and create canvas tags for them. For example: create corresponding canvases for the fragments with odd positions in the above list, and define an attribute id='canvas-'+index for the canvas, where index is the position of the current fragment, and the remaining fragments are still displayed in the form of text. In addition, you can also create corresponding canvases for the fragments with even positions in the above list, or set characters at each interval, extract at least one character from the list, etc., without limitation here. Figure 2 As shown, the data to be kept confidential is "I am a text", and the data is segmented according to one character corresponding to one data segment, and a set of data segments is obtained: ['I', 'is', 'one', 'one', 'text', 'book']; select the data segments with odd positions and create a canvas; the position is judged as: index%2 !==0.
[0033] Create a method to draw text to the canvas and call it after the page is rendered. Traverse the list and determine the position index of each item. When the index meets the rule defined in step 3 (odd position: index%2 !==0), draw the item to the canvas with id='canvas-'+index through the fillText() method of the canvas API. At this time, the item can be displayed normally on the page.
[0034] When all items are traversed and executed, the extracted data fragments are drawn in the corresponding canvas and displayed normally on the page like other data fragments that are not drawn in the canvas. From the developer's perspective, the types of these two text fragments are different. For example, the first character 2 in the list is a text, and the second character 0 is a canvas, but this type difference does not make a difference when displayed on the page, and you will see a normal text: 2024-05-05.
[0035] The present invention improves development efficiency and reduces costs: based on canvas drawing text, the code difficulty is relatively low, the time of using other anti-crawler methods is reduced, the development cost is reduced, the development efficiency is improved, and the anti-crawling difficulty is increased.
[0036] Embodiment 2 This embodiment provides an anti-crawler system based on canvas drawing text.
[0037] An anti-crawler system based on canvas text drawing, comprising: A segmentation module is configured to: obtain the data to be kept confidential, segment the data to be kept confidential according to a set rule, and obtain a set of data segments and position arrangement information of the data segments; A canvas creation module is configured to: traverse the data segment set, extract some data segments from the data segment set according to a set rule, create canvases for the extracted some data segments, and obtain a first canvas set; A canvas drawing module is configured to: based on the position arrangement information of the data fragments, draw the data fragments at the corresponding position of each canvas in the canvas set into the corresponding canvas to obtain a second canvas set; The page arrangement module is configured to: arrange the unextracted data segments and the second canvas set in the page according to the position arrangement information of the data segments.
[0038] In some embodiments, the data to be kept confidential are segmented according to a set rule, and the method includes: if the length of the data to be kept confidential is less than a set threshold, the data to be kept confidential are segmented according to one character corresponding to one data segment.
[0039] In one or more embodiments, the data to be kept confidential is segmented according to a set rule, and the method further includes: if the length of the data to be kept confidential is greater than or equal to a set threshold, the data to be kept confidential is segmented according to at least two characters corresponding to one data segment.
[0040] In some embodiments, a method for extracting some data segments from a data segment set according to a set rule includes: extracting data segments of odd bits in the data segment set; or extracting data segments of even bits in the data segment set; or setting data segments at intervals and extracting at least one data segment from the data segment set, etc. This embodiment is not limited here.
[0041] In some embodiments, the method for obtaining the data to be kept confidential includes: obtaining the data to be kept confidential that has been encrypted by the national encryption SM4 through an interface for obtaining content information.
[0042] The present invention provides an anti-crawler system based on canvas text drawing. The data rendered in the web page is divided and drawn into the canvas respectively. The data in the source code is invisible, so crawler technicians are prevented from crawling key data information in the web page source code. After the canvas is converted into a picture for download, the text extracted by character recognition technology is also a plurality of disordered text fragments, which are unreadable, thereby ensuring data security.
[0043] Embodiment 3 This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps in the anti-crawler method based on canvas drawing text as described in the first embodiment above are implemented.
[0044] Embodiment 4 This embodiment provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps in the anti-crawler method based on drawing text on a canvas as described in the first embodiment are implemented.
[0045] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. An anti-crawler method based on canvas drawing text, It is characterized in that include: Acquire the data to be kept confidential, segment the data to be kept confidential according to the set rules, and obtain a set of data segments and position arrangement information of the data segments; Traversing the data fragment set, extracting some data fragments from the data fragment set according to a set rule, creating canvases for the extracted some data fragments, and obtaining a first canvas set; Based on the position arrangement information of the data fragments, the data fragments at the corresponding positions of each canvas in the canvas set are drawn into the corresponding canvas to obtain a second canvas set; Arrange the unextracted data segments and the second canvas set in the page according to the positions of the data segments; The data to be kept confidential are segmented according to a set rule, the method comprising: if the length of the data to be kept confidential is less than a set threshold, the data to be kept confidential are segmented according to one character corresponding to one data segment; If the length of the data to be kept confidential is greater than or equal to a set threshold, the data to be kept confidential is divided into data segments corresponding to at least two characters.
2. The anti-crawler method based on canvas drawing text according to claim 1, It is characterized in that Extracting some data segments from a data segment set according to a set rule, the method includes: extracting odd-numbered data segments from the data segment set.
3. The anti-crawler method based on canvas drawing text according to claim 1, It is characterized in that Part of the data segments are extracted from the data segment set according to a set rule. The method also includes: extracting data segments with even digits in the data segment set.
4. The anti-crawler method based on canvas drawing text according to claim 1, It is characterized in that Part of the data segments are extracted from the data segment set according to the set rules. The method also includes: setting the data segments at each interval and extracting at least one data segment from the data segment set.
5. The anti-crawler method based on canvas drawing text according to claim 1, It is characterized in that The method for obtaining the data to be kept confidential includes: obtaining the data to be kept confidential that has been encrypted by the national encryption SM4 through the content information acquisition interface.
6. An anti-crawler system for drawing text on a canvas based on the method according to any one of claims 1 to 5, It is characterized in that include: A segmentation module is configured to: obtain the data to be kept confidential, segment the data to be kept confidential according to a set rule, and obtain a set of data segments and position arrangement information of the data segments; A canvas creation module is configured to: traverse the data segment set, extract some data segments from the data segment set according to a set rule, create canvases for the extracted some data segments, and obtain a first canvas set; A canvas drawing module is configured to: based on the position arrangement information of the data fragments, draw the data fragments at the corresponding position of each canvas in the canvas set into the corresponding canvas to obtain a second canvas set; The page arrangement module is configured to: arrange the unextracted data segments and the second canvas set in the page according to the position arrangement information of the data segments.
7. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the steps in the anti-crawler method based on drawing text on a canvas as described in any one of claims 1 to 5 are implemented.
8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the steps in the anti-crawler method based on canvas drawing text as described in any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Anti-crawler data processing method, browser, computer equipment and storage medium
CN111339548A
Webpage content processing method and device, electronic equipment and storage medium
CN114722321A
