Crawler detection method, electronic equipment and storage medium
By carrying a preset script in the response data returned by the server to obtain the user interface layout parameters and combining it with a machine learning model for crawler detection, the problem that existing technology cannot accurately identify crawlers based on the built-in browser kernel is solved, and access security is improved.
Patent Information
- Application Number
- CN202410890381.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-03
- Publication Date
- 2024-10-15
AI Technical Summary
Existing anti-crawler solutions cannot accurately detect crawlers based on the built-in browser kernel, resulting in insufficient access security.
By carrying the preset script in the response data returned by the server, the client runs the script to obtain the user interface layout parameters and uses them for crawler detection. It combines the machine learning model to generate a probability matrix for crawler identification and interception.
It achieves accurate detection and interception of crawlers based on the built-in browser kernel, improves access security and avoids the harm caused by crawlers.
Smart Images

Figure CN118784308A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of network security technology, and in particular to a crawler detection method, electronic device, and storage medium. Background Art
[0002] With the explosive growth of Internet data, data has become the "oil" of the new era. In order to collect data from the Internet more conveniently, various crawler implementation solutions have been proposed. Among them, crawlers refer to technologies that automatically grab content from the Internet according to certain rules. Crawlers bring some access security issues to the Internet, such as excessive server load, data being stolen, abused or distorted by competitors, and user privacy leaks. Therefore, various anti-crawler solutions have also been proposed, such as:
[0003] Anti-crawler solutions based on request analysis, that is, identifying crawlers by analyzing the request features sent by the client, including: user agent detection, IP address and frequency restrictions, Transport Layer Security (TLS) fingerprint identification, etc. Technology based on content and interaction challenges, that is, blocking or delaying crawlers by increasing the complexity of human-computer interaction, including: graphic verification codes, slider verification codes, etc. Technology based on the architecture and protocol level, that is, increasing the difficulty of crawlers by using the characteristics of Web technology and communication protocols, including: hidden fields and obfuscation technology, dynamically generating or changing website content and structure, making it difficult for crawlers to predict and crawl. Technology based on client behavior analysis, that is, behavior-based analysis and browser fingerprint identification, including: monitoring whether mouse clicks, scrolling, movement and other behaviors conform to normal human behavior patterns, and identifying clients by collecting attribute information of various browsers and combining them into fingerprint information.
[0004] However, the above typical anti-crawler schemes have gradually produced corresponding solutions. For example, proxy pools are used to bypass policies based on IP addresses and frequency restrictions, and image recognition technology is used to automatically input graphic verification codes. Some advanced crawler tools can completely match the way humans browse web pages, simulate human operation behaviors, and bypass detection by built-in attribute information of real common browsers. Summary of the invention
[0005] The embodiments of the present application provide a crawler detection method, an electronic device, and a storage medium, which at least facilitate more accurate detection of crawlers and improve access security.
[0006] According to some embodiments of the present application, a first aspect of the embodiments of the present application provides a crawler detection method, which is applied to a server, and the method includes: receiving a first access request sent by a client; sending first response data to the client, wherein the first response data carries a preset script; receiving a second access request sent by the client, wherein the second access request carries user interface layout parameters obtained by the client by running the preset script; and performing crawler detection according to the user interface layout parameters.
[0007] In some embodiments, the user interface layout parameters include at least one of the following parameters: window width, viewport width, window height, viewport height.
[0008] In some embodiments, the user interface layout parameters include at least one of the following groups: the window width and the viewport width, the window height and the viewport height; the crawler detection based on the user interface layout parameters includes: generating a first characteristic parameter based on the window width and the viewport width, and / or generating a second characteristic parameter based on the window height and the viewport height; performing crawler detection based on the first characteristic parameter and / or the second characteristic parameter.
[0009] In some embodiments, the first characteristic parameter is determined by the following expression: Y1=X1 / X2, wherein Y1 is the first characteristic parameter, X1 is the window width, and X2 is the viewport width; and / or, the second characteristic parameter is determined by the following expression: Y2=X3 / X4, wherein Y2 is the second characteristic parameter, X3 is the window height, and X4 is the viewport height.
[0010] In some embodiments, performing crawler detection according to the user interface layout parameters includes: generating a probability matrix according to the user interface layout parameters and a trained machine learning model, wherein the probability matrix is used for the probability that the access behavior is crawler behavior and / or the probability that the access behavior is normal; performing crawler detection according to the probability matrix.
[0011] In some embodiments, the machine learning model is a support vector machine model.
[0012] In some embodiments, performing crawler detection according to the probability matrix includes: performing crawler detection according to the probability matrix and reference information, wherein the reference information includes at least one of the following information: user behavior, client information.
[0013] In some embodiments, the method further includes: if the detection is successful, sending second response data to the client; and / or, if the detection is not successful, intercepting the second access request.
[0014] In some embodiments, the preset script is located in the web page data in the first response data. <header>The user interface layout parameters are located in a cookie.
[0015] According to some embodiments of the present application, the second aspect of the embodiments of the present application also provides a crawler detection method, which is applied to a client, and the method includes: sending a first access request to a server; receiving first response data returned by the server, wherein the first response data carries a preset script; presenting a web page according to the first response data, and running the preset script to collect user interface layout parameters corresponding to the web page; sending a second access request to the server, wherein the second access request carries the user interface layout parameters.
[0016] According to some embodiments of the present application, the third aspect of the embodiments of the present application also provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute any crawler detection method provided in the first aspect of the present application, or execute any crawler detection method provided in the second aspect of the present application.
[0017] According to some embodiments of the present application, the fourth aspect of the embodiments of the present application further provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any crawler detection method provided in the first aspect of the present application, or implements any crawler detection method provided in the second aspect of the present application.
[0018] The technical solution provided in the embodiments of the present application has at least the following advantages:
[0019] When responding to the first access request initiated by the client, the first response data returned by the server carries a preset script, so that after receiving the first response data, the client will obtain the user interface layout parameters by running the preset script carried therein, so that the client will support sending a second access request carrying the user interface layout parameters, so that the server can perform crawler detection through the user interface layout parameters. In other words, a new access scheme for detecting and intercepting crawlers through user interface layout parameters is provided, which can make up for the defect that the existing anti-crawler scheme cannot accurately detect crawlers based on the built-in browser kernel, so that crawlers can be detected more accurately, problems caused by crawlers are avoided, and access security is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0021] Figure 1 This is the process of the crawler detection method provided in the embodiment of this application Figure 1 ;
[0022] Figure 2 Is the response data of the existing access request <header>Code diagram of the label;
[0023] Figure 3 It is the first response data involved in the crawler detection method provided in the embodiment of the present application. <header>Code diagram of the label;
[0024] Figure 4 is a schematic diagram of the window area and viewport area involved in the crawler detection method provided in the embodiment of the present application;
[0025] Figure 5 is another schematic diagram of the window area and viewport area involved in the crawler detection method provided in the embodiment of the present application;
[0026] Figure 6 This is the process of the crawler detection method provided in the embodiment of this application Figure 2 ;
[0027] Figure 7 This is the process of the crawler detection method provided in the embodiment of this application Figure 3 ;
[0028] Figure 8 This is the process of the crawler detection method provided in the embodiment of this application Figure 4 ;
[0029] Fig. 9 This is the process of the crawler detection method provided in the embodiment of this application Figure 5 ;
[0030] Fig.10 It is an interactive flow chart of the crawler detection method provided in the embodiment of the present application;
[0031] Fig.11 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the embodiments of the present application will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in the embodiments of the present application, many technical details are provided in order to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can be implemented.
[0033] The division of the following embodiments is for the convenience of description and shall not constitute any limitation on the specific implementation of the present application. The embodiments may be combined with each other and referenced to each other without contradiction.
[0034] The first aspect of the embodiment of the present application provides a crawler detection method, which is applied to a server. The server may be an intermediate server, that is, a server that forwards requests, responses, etc. between a source station and a client, such as a content delivery network (CDN) server, a transit server, etc.; the server may also be a source station server. In the embodiment of the present application, this is not limited.
[0035] When the crawler detection method provided in the embodiment of the present application is applied to the server, the server adds a preset script to the response data returned to the client, so that on the client, the user interface layout parameters of the web page presented by the browser of the client can be automatically collected based on the preset script, and the request initiated by the client again is fed back to the server, so that the server can obtain the user interface layout parameters of the client and perform crawler detection to intercept the access request initiated by the crawler. A new crawler detection and interception scheme is implemented in the access process, and because this idea is a new idea for detecting crawlers based on the built-in browser kernel, it can make up for the defect that the existing anti-crawler scheme cannot accurately detect crawlers based on the built-in browser kernel, so that crawlers can be detected and intercepted more accurately, avoiding the harm caused to the server by crawler-based access, and improving the security of access.
[0036] To facilitate those skilled in the art to better understand the above, the crawler detection method applied to the server will be described below in combination with different embodiments.
[0037] like Figure 1 As shown, in some embodiments, the process of the crawler detection method applied to the server may include the following steps:
[0038] Step 101: Receive a first access request sent by a client.
[0039] Step 102: Send first response data to the client, wherein the first response data carries a preset script.
[0040] Step 103: receiving a second access request sent by the client, wherein the second access request carries a user interface (UI) layout parameter obtained by the client by running a preset script.
[0041] Step 104: perform crawler detection according to the user interface layout parameters.
[0042] In this way, when responding to the first access request initiated by the client, the first response data returned by the server carries a preset script, so that after receiving the first response data, the client will obtain the user interface layout parameters by running the preset script carried therein, so that the client will support sending a second access request carrying the user interface layout parameters, so that the server can perform crawler detection through the user interface layout parameters. In other words, a new access scheme for crawler detection and interception through user interface layout parameters is provided, which can make up for the defect that the existing anti-crawler scheme cannot accurately detect crawlers based on the built-in browser kernel, so that crawlers can be detected more accurately. In particular, it is able to accurately detect and intercept access achieved by existing crawler tools such as Houyi Collector and Octopus Collector that provide built-in browser kernels and graphical interfaces. Among them, the browsers in the existing crawler tools that provide built-in browser kernels and graphical interfaces are limited by the limitations of the user interface of the crawler tools, and the user interface layout of the presented web pages is usually difficult to be the same as the web pages presented by the real client, that is, the user interface layout parameters corresponding to the crawler tool are different from the user interface layout parameters corresponding to the real client. Therefore, the detection of the crawler can be achieved based on the user interface layout parameters.
[0043] In step 101, the client may be any device or apparatus capable of initiating an access request; the first access request may be any request capable of initiating an access. For example, the client may be a user device of a normal user; for another example, the client may also be a device of a crawler (a user who collects data through crawler technology). For example, the first access request may be a Hypertext Transfer Protocol (HTTP) request; for another example, the first access request may also be a Hypertext Transfer Protocol Secure (HTTPS); for another example, the first access request may be an access request for any website; for another example, the first access request may be an access request for a specific website, etc. The client and the first access request will not be listed one by one here.
[0044] It should be noted that, in the embodiment of the present application, the "first" in the "first access request" is mainly used to distinguish it from the subsequent "second access request", that is, to distinguish between requests carrying "user interface layout parameters" and requests not carrying "user interface layout parameters", and it has no other meaning.
[0045] In step 102, the fact that the first response data carries a preset script does not mean that the first response data only includes the preset script. It is understandable that the first response data also includes response data for the first access request, such as web page data. The embodiment of the present application does not limit the web page data and the preset script in the first response data. The web page data in the first response data can be any data that can be used to arrange a user interface and present a web page (or a similar web page). The preset script can be any script that can collect and process the user interface layout parameters of the browser's web page to set the user interface layout parameters to the access request when the next access is initiated. For example, the web page data in the first response data can also be fictitious web page data, that is, the web page obtained by the client through the first response data is not a web page provided by a real website, or is not a web page provided by the website that the client wants to visit. In this way, by presenting web page data other than what is needed to the client, it is avoided to expose the real web page data to the crawler, and the data security in the access process is further improved. For another example, the web page data in the first response data can be real web page data, that is, the web page obtained by the client through the first response data is provided by a real website. In this way, it is possible to intercept the crawler-based access through the subsequent interception operation of the second access request, thereby ensuring security, and can always present the real web page to normal users. The web page is forwarded to the crawler, which avoids interference with normal user access and can improve user experience. The first response data is only the response result of a visit. Even if it is fed back to the crawler, it will not actually cause data leakage, the impact can be ignored, and data security can still be guaranteed. For example, the web page data in the first response data can also be fictitious web page data, but the server supports the client to convert the second access request initiated on the fictitious web page data (for example, mapping on different web pages based on the click position, or mapping based on the correspondence between the user interface components on the fictitious web page and the real web page, etc.), and obtain the access request corresponding to the real web page, so as to simultaneously avoid data leakage to the crawler and ensure the user experience of real users. For example, the preset script can be a JS (JavaScript) script, etc.; for example, the preset script can be located in the web page data in the first response data. <header>tag.
[0046] To facilitate those skilled in the art to better understand the preset script and the way in which the first response data carries the preset script, the following will be combined with Figure 2 and Figure 3 Provide explanation.
[0047] like Figure 2 As shown, the code is the response data of the first access request in the existing solution. <header>The first response data carrying the preset script provided in the embodiment of the present application <header>The tag code is as follows Figure 3 As shown, Figure 3 The code circled in the figure is the preset script, Figure 3 is Figure 2 On the basis of Figure 3 The code circled in (i.e. the preset script).
[0048] It should be noted that Figure 3 The preset script shown is only a code example. In some embodiments, the preset script may also be composed of codes such as window.outerWidth, window.outerHeight, window.innerWidth, window.innerHeight, etc. The code contents of the preset script are not listed one by one here.
[0049] It should also be noted that the embodiments of the present application do not limit the manner in which the server obtains the web page data in the first response data. For example, when the server is an intermediate server, the web page data in the first response data can be first obtained locally. If it cannot be obtained locally (for example, when the server is a CDN edge server, a cache miss means that it cannot be obtained locally), then it is necessary to forward the request to the source station to obtain the web page data in the first response data from the source station, and the server then inserts the preset script into the web page data returned by the source station. For example, when the server is the source station, the first response data obtains the response data locally and inserts the preset script, etc., which will not be listed one by one here.
[0050] In addition, the embodiments of the present application do not limit the user interface layout parameters, which can be any one or some parameters related to the user interface layout and can reflect the differences between the crawler and the normal user interface. For example, the user interface layout parameters can include: the arrangement of user interface elements; for example, the user interface layout parameters can also include: the type of user interface elements; for example, the user interface layout parameters include: window width and height, viewport width and height, etc. The user interface layout parameters will not be listed one by one here.
[0051] Among them, window and viewport have different meanings. Specifically, Figure 4 and Figure 5 As shown, the area surrounded by blue lines (including the area surrounded by red lines inside it) is the window, including the browser's border, tab bar, scroll bar, toolbar, etc.; the area surrounded by red lines is the viewport, which is the size of the area where the web page content is actually displayed, excluding the browser's UI components. Different browsers have different UI layout styles, especially the gap between crawler tools and normal browsers is more obvious.
[0052] In some embodiments, the user interface layout parameters may include at least one of the following parameters: window width, viewport width, window height, viewport height.
[0053] It is understandable that the window width and viewport width and height provided by the crawler tool are significantly different from the window width and height and viewport width and height provided by normal users for web page presentation, and the parameters are easy to obtain and process, with a small amount of data and easy transmission, which can improve crawler detection efficiency.
[0054] It can also be understood that normal users have zooming operations on browser pages. At the same time, the maximum minimization degree of the browser page, the display size of the client and its resolution are different, so the specific values of the window width and height and the viewport width and height of the normal user interface layout vary. In other words, if the parameters of the window or viewport are used alone for crawler detection (for example, detection based on the window determined by the window width and height, or detection based on the viewport determined by the viewport width and height, etc.), it may be affected by page zooming and insufficient display data collection, etc., and the normal user access may be misjudged as a crawler, thereby affecting the experience of normal users. Based on this, in some embodiments, the user interface layout parameters include at least one of the following groups: window width and viewport width, window height and viewport height. In this way, by combining the window and viewport parameters, based on the usually stable association relationship between the window and the viewport of the normal client, the interference caused by the specific values of the window parameters and the viewport parameters is overcome, which is conducive to more accurate crawler detection, thereby improving the security of access.
[0055] At this time, if Figure 6 As shown, in the crawler detection method applied to the server, crawler detection according to the user interface layout parameters can be implemented by the following steps:
[0056] Step 604: Generate a first characteristic parameter according to the window width and the viewport width, and / or generate a second characteristic parameter according to the window height and the viewport height.
[0057] Step 605: Perform crawler detection based on the first characteristic parameter and / or the second characteristic parameter.
[0058] in, Figure 6 Steps 601 to 603 in the illustrated embodiment are Figure 1 Steps 101 to 103 in the illustrated embodiment are substantially the same and will not be described in detail herein.
[0059] in, Figure 6 The illustrated embodiment does not limit the specific generation method of the first characteristic parameter and the second characteristic parameter, which can be determined based on the observed difference in the window and viewport association relationship between the crawler tool and the normal user client.
[0060] For example, in some embodiments, the first characteristic parameter is determined by the following expression:
[0061] Y1=X1 / X2;
[0062] Among them, Y1 is the first characteristic parameter, X1 is the window width, and X2 is the viewport width;
[0063] In some embodiments, the second characteristic parameter is determined by the following expression:
[0064] Y2=X3 / X4;
[0065] Among them, Y2 is the second characteristic parameter, X3 is the window height, and X4 is the viewport height.
[0066] The ratio of the window parameter to the viewport parameter is more stable for normal clients. Based on this as a characteristic parameter, it is possible to more accurately distinguish between access initiated by normal users and access initiated by crawlers, that is, crawler detection can be performed more accurately, thereby further improving access security.
[0067] For example, after generating corresponding feature data for the window width and viewport width of the page presented by different crawler tools and normal user's client according to the above method, these data are converted into (type, first feature parameter, second feature parameter), and the first feature parameter is used as the horizontal axis, the second feature parameter is used as the vertical axis, and different types are distinguished by different colors, and a scatter plot is created. Through the scatter plot, it can be clearly seen that the point sets of different types of browsers and crawler tools are highly separable, that is, the above expression is processed to perform crawler detection with high accuracy. Among them, the type is used to indicate whether the data comes from the web page presented on the crawler tool or the web page presented on the client of the normal user.
[0068] Of course, the above is only an exemplary explanation of the generation of the first characteristic parameter and the second characteristic parameter. In some embodiments, the window parameters and viewport parameters of the client of the normal user, as well as the window parameters and viewport parameters of the crawler tool, which have been obtained, can be clustered, and the clustered data can be fitted and processed to find a characteristic representation that can distinguish between the client of the normal user and the crawler tool, and the processing method corresponding to the characteristic representation can be used as the generation method of the first characteristic parameter and the second characteristic parameter, etc., which will not be described one by one here.
[0069] In step 103, the second access request is not limited, and can be any access request initiated by a web page presented based on the first response data, carrying user interface layout parameters obtained by the client by running a preset script. For example, the first access request can be a Hypertext Transfer Protocol (HTTP) request; for another example, the first access request can also be a Hypertext Transfer Protocol Secure (HTTPS). The second access requests will not be listed one by one here.
[0070] It is understandable that after receiving the first response data, the client will render based on the web page data therein to present the web page. After the web page is presented, the user interface layout parameters will be automatically collected based on a preset script, and written into the second access request when the second access request is subsequently initiated.
[0071] It should be noted that the embodiment of the present application does not limit the way in which the user interface layout parameters are carried in the second access request. For example, the user interface layout parameters can be carried in a cookie, that is, after the preset script runs to collect the user interface layout parameters, a corresponding cookie will be generated. In this way, when the client initiates an access request again, a second access request carrying the user interface layout parameters will be automatically formed based on the cookie; for example, the user interface layout parameters can be carried in an extended field of the request, that is, the user interface layout parameters are written into the access request through a preset script to form a second access request, etc., which will not be described one by one here.
[0072] It should also be noted that some crawler tools may not have a user interface, and the user interface layout parameters will not be collected at this time. Accordingly, the access request initiated again will not carry the user interface layout parameters, but the client of a normal user will definitely pass the user interface layout parameters to the server, unless the access is abandoned or the second access request is abandoned. Therefore, when the server detects that the access initiated again by the same client to the same source station does not carry the user interface layout parameters, it can be directly judged as a crawler.
[0073] In addition, the second access request does not refer to one access, but may refer to multiple access requests after the first access request, which will not be described one by one here.
[0074] In step 104, the implementation method of crawler detection is not specifically limited. For example, the implementation method can be as follows: Figure 6 As shown. Among them, when performing crawler detection based on the first characteristic parameter and / or the second characteristic parameter, it can be specifically detected by whether it falls into the range corresponding to the client of the crawler or the normal user constructed by the threshold. Of course, it can be understood that the selection of the threshold usually needs to rely on experience or experiments, etc., and its usual meaning is relatively limited. Therefore, in some embodiments, a machine learning model can also be used for processing to further understand its potential connections through the machine learning model without relying on experiments or manual experience. For example, the first characteristic parameter and / or the second characteristic parameter are used as the input features required by the machine learning model, and the probability of the output of the machine learning model is obtained as the result of the detection, etc. It can also be understood that the processing of the machine learning model is not limited to the first characteristic parameter and / or the second characteristic parameter, and the user interface layout parameters can also be directly or indirectly used as input parameters, etc.
[0075] That is, in some embodiments, Figure 7 As shown, detection based on the user interface layout parameters can be achieved through the following steps:
[0076] Step 704, generating a probability matrix based on the user interface layout parameters and the trained machine learning model, wherein the probability matrix is used for the probability that the access behavior is a crawler behavior and / or the probability that the access behavior is normal.
[0077] Step 705: Perform detection according to the probability matrix.
[0078] in, Figure 7 In the embodiment shown, steps 701 to 703 are Figure 1 Steps 101 to 103 in the illustrated embodiment are substantially the same and will not be described in detail herein.
[0079] It should be noted that Figure 7 The illustrated embodiment does not limit the machine learning model, which can be any machine learning model. For example, in some embodiments, the machine learning model is a support vector machine (SVM) model. An optimal hyperplane (or decision boundary) is found through the support vector machine model to maximize the interval between the user interface layout parameters corresponding to the client of a normal user and the crawler, thereby achieving the purpose of classification detection. In other words, the support vector machine model is more suitable for judging crawler detection scenarios, especially being able to adapt to situations where there are differences between data of the same category due to different scaling, display screen size and resolution, which is conducive to improving the accuracy of detection and further improving the security of access.
[0080] It should also be noted that in order to further improve the accuracy of crawler detection, crawler detection can be further combined with other strategies. For example, in some embodiments, crawler detection based on the probability matrix can be implemented in the following way: crawler detection is performed based on the probability matrix and reference information, wherein the reference information includes at least one of the following information: user behavior, client information. Of course, the above is only an exemplary description of crawler detection for the probability matrix output by the machine learning model combined with other measurements. In some embodiments, detection can also be directly combined with user interface layout parameters, or it can also be combined with other crawler strategies, such as detection based on IP addresses, etc., which will not be described one by one here.
[0081] in, Figure 7 The illustrated embodiment does not limit the training method of the machine learning model. Mainly, during training, the same browser or crawler tool collects as much width and height attribute data as possible under different systems, different sizes and different resolution displays, and different zoom window sizes, and the data is annotated with the browser or crawler tool to which it belongs, wherein the data source crawler is annotated with the client of a normal user. For example, a web test website is built, and the webpage content is to obtain the browser's window width and height, viewport width and height, and user-agent type through JS. Use chrome, edge, Firefox, Houyi collector, octopus collector, etc. to access the test website under multiple displays, and obtain as much window width and height and viewport width and height data in different scenarios as possible by dragging and scaling the size of the browser and crawler tool. The training method can be different based on the different machine learning models. Taking the support vector machine model as an example, the window width and height and viewport width and height collected above are processed as mentioned above to obtain the first feature parameter and the second feature parameter, and then the feature data carrying the type label is constructed. 80% of them are used as the training set and 20% as the test set. The training is carried out using a specified one-to-one strategy and a radial basis kernel function (RBF) as well as the hyperparameters of the optimization model.
[0082] It is also understandable that after performing crawler detection, the second access request can be further processed according to the detection results. For example, if a crawler is detected, the second access request can be directly intercepted. It can also be considered that the detection is not necessarily completely accurate. Once the user request is rejected, it will easily affect the user experience. Therefore, a preset number of crawler detection requests initiated by the same client are responded to, and only when crawlers exceeding the preset number are detected, interception is performed, etc. Among them, the embodiment of the present application does not limit the interception method, which can be directly discarding the second access request and no longer processing, or stopping forwarding the second access request to the source station, etc., which will not be repeated here.
[0083] It is also understandable that the crawler detection may not only fail, but also pass. Figure 8 As shown, after performing crawler detection according to the user interface layout parameters, if the detection fails, that is, a crawler is detected, the processing strategy at this time is to intercept the second access request; if the detection passes, that is, no crawler is detected, then the strategy at this time is to process the second response data normally, that is, send the second response data to the client. The second response data is the web page data requested to be accessed by the second access request, etc., which will not be described one by one here.
[0084] Accordingly, the present application also provides a crawler detection method on the other hand, which is applied to a client, and the client can be a user device of a normal user or a device of a crawler. Fig. 9 As shown, the process of the crawler detection method applied to the client includes the following steps:
[0085] Step 901: Send a first access request to a server.
[0086] Step 902: Receive first response data returned by the server, wherein the first response data carries a preset script.
[0087] Step 903: presenting a web page according to the first response data, and running a preset script to collect user interface layout parameters corresponding to the web page.
[0088] Step 904: Send a second access request to the server, where the second access request carries user interface layout parameters.
[0089] In this way, after initiating a first access request to the server, the first response data carrying a preset script will be received. In this way, the user interface layout parameters will be acquired by running the preset script carried therein, thereby supporting the sending of a second access request carrying the user interface layout parameters, so that the server can perform crawler detection through the user interface layout parameters to intercept the access request initiated by the crawler and intercept the crawler. In other words, a new access scheme for crawler detection and interception through user interface layout parameters is provided, which can make up for the defect that the existing anti-crawler scheme cannot accurately detect crawlers based on the built-in browser kernel, so that crawlers can be detected more accurately, and then the access security can be improved by better intercepting the access initiated by the crawler.
[0090] It should be noted that the crawler detection method applied to the client provided in the above embodiment corresponds to the crawler detection method applied to the server provided in the above embodiment, and the above embodiment can be implemented in conjunction with the method embodiment applied to the server. The relevant technical details mentioned in the method embodiment applied to the server are still valid in this embodiment, and in order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied in the method embodiment applied to the server.
[0091] To help those skilled in the art better understand the crawler detection method provided in the above embodiment, the interaction process of the crawler detection method between the server (CDN edge server) and the client is described below.
[0092] like Fig.10 As shown, the interaction process includes the following steps:
[0093] Step 1001: The client sends a first access request.
[0094] Step 1002: The server performs a cache hit detection based on the received first access request.
[0095] Step 1003, in the case of a cache hit, the server adds a preset script to the hit data and returns it to the client as the first response data.
[0096] Step 1004: in case of a cache miss, the server forwards the first access request to return to the source, wherein the first access request may be forwarded directly to the source station or to a superior server.
[0097] Step 1005: The server receives the returned web page data.
[0098] Step 1006: After receiving the webpage data returned from the source and adding the preset script, the server returns it to the client as the first response data.
[0099] Step 1007: The client performs rendering based on the first response data to present a response page to the user, and at the same time runs a script preset in the first response data to obtain user interface layout parameters and generate corresponding cookies.
[0100] Step 1008: The client initiates a second access request and carries a cookie corresponding to the user interface layout parameter in the second access request.
[0101] Step 1009: The server parses the user interface layout parameters in the second access request, and performs crawler detection based on the parameters.
[0102] Step 1010: If the detection passes, the server performs a cache hit detection.
[0103] Step 1011, in case of a cache hit, the server returns the hit data as second response data to the client.
[0104] Step 1012: In case of a cache miss, the server forwards the second access request to return to the source.
[0105] Step 1013: The server receives the second response data returned by returning to the source.
[0106] Step 1014: The server forwards the second response data to the client.
[0107] Step 1015: If the detection fails, the server intercepts the second access data.
[0108] in, Fig.10 The solid and dotted lines of the arrows and boxes are used to distinguish the different steps performed under different conditions.
[0109] It can be seen that the first access request can be a normal request. However, the first response data is different from the normal response data, and it also carries a preset script. The second access request is different from the normal access request, and it also carries a preset script, but the second response data is the same as the normal response data.
[0110] The step division of the above methods is only for the purpose of clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0111] Another aspect of the present application embodiment further provides an electronic device, such as Fig.11 As shown, it includes: at least one processor 1101; and a memory 1102 that is communicatively connected to the at least one processor 1101; wherein the memory 1102 stores instructions that can be executed by the at least one processor 1101, and the instructions are executed by the at least one processor 1101 so that the at least one processor 1101 can execute the crawler detection method described in any of the above method embodiments.
[0112] Among them, the memory 1102 and the processor 1101 are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors 1101 and the memory 1102 together. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are all well known in the art, and therefore, are not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor 1101 is transmitted on a wireless medium through an antenna, and further, the antenna also receives data and transmits the data to the processor 1101.
[0113] The processor 1101 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 1102 can be used to store data used by the processor 1101 when performing operations.
[0114] Another aspect of the present application embodiment further provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the above method embodiment is implemented.
[0115] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including a number of instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program scripts.
[0116] Those skilled in the art will appreciate that the above embodiments are specific embodiments for implementing the present application, and in actual applications, various changes may be made thereto in form and detail without departing from the spirit and scope of the present application.< / header> < / header> < / header> < / header> < / header> < / header>
Claims
1. A crawler detection method, characterized in that: Applied to a server, the method comprises: receiving a first access request sent by a client; Sending first response data to the client, wherein the first response data carries a preset script; Receiving a second access request sent by the client, wherein the second access request carries the user interface layout parameters obtained by the client by running the preset script; Crawler detection is performed according to the user interface layout parameters.
2. The crawler detection method according to claim 1, characterized in that: The user interface layout parameters include at least one of the following parameters: window width, viewport width, window height, and viewport height.
3. The crawler detection method according to claim 2, characterized in that: The user interface layout parameters include at least one of the following: the window width and the viewport width, the window height and the viewport height; The performing crawler detection according to the user interface layout parameters includes: generating a first characteristic parameter according to the window width and the viewport width, and / or generating a second characteristic parameter according to the window height and the viewport height; Crawler detection is performed according to the first characteristic parameter and / or the second characteristic parameter.
4. The crawler detection method according to claim 3, characterized in that: The first characteristic parameter is determined by the following expression: Y1=X1 / X2, Wherein, Y1 is the first characteristic parameter, X1 is the window width, and X2 is the viewport width; and / or, The second characteristic parameter is determined by the following expression: Y2=X3 / X4, Among them, Y2 is the second characteristic parameter, X3 is the window height, and X4 is the viewport height.
5. The crawler detection method according to any one of claims 1 to 4, characterized in that: The performing crawler detection according to the user interface layout parameters includes: Generate a probability matrix according to the user interface layout parameters and the trained machine learning model, wherein the probability matrix is used for the probability that the access behavior is a crawler behavior and / or the probability that the access behavior is normal; Crawler detection is performed according to the probability matrix.
6. The crawler detection method according to claim 5, characterized in that: The performing crawler detection according to the probability matrix includes: Crawler detection is performed according to the probability matrix and reference information, wherein the reference information includes at least one of the following information: user behavior, client information.
7. The crawler detection method according to any one of claims 1 to 4, characterized in that: The method further comprises: If the detection is successful, sending second response data to the client; and / or, If the detection fails, the second access request is intercepted.
8. The crawler detection method according to any one of claims 1 to 4, characterized in that: The preset script is located in the web page data in the first response data. <header>The user interface layout parameters are located in a cookie.
9. A crawler detection method, characterized in that: Applied to a client, the method comprises: Sending a first access request to the server; Receiving first response data returned by the server, wherein the first response data carries a preset script; Presenting a web page according to the first response data, and running the preset script to collect user interface layout parameters corresponding to the web page; A second access request is sent to the server, where the second access request carries the user interface layout parameter.
10. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the crawler detection method as described in any one of claims 1 to 8, or execute the crawler detection method as described in claim 9.
11. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the crawler detection method according to any one of claims 1 to 8 is implemented, or the crawler detection method according to claim 9 is implemented. < / header>
