This article introduces how dynamic websites generate static pages with a large number of examples from the perspective of an ASP programmer, from the perspective of a collection program developer, I introduced in detail the principles of website data collection and defense policies.
To make it easy for readers of this article to understand how websites generate static pages, this article lists several common methods for generating static pages. Many instance codes are used to describe them.
With regard to website data collection attack and defense, the author is a developer of the collection program. At the same time, the author has collected and studied a variety of collection programs and listed several popular anti-collection policies in China, and made a simple and objective analysis and evaluation of each strategy, hoping to provide some help to the majority of webmasters. This chapter also provides the author's original anti-collection methods to help you understand the feasibility and effectiveness of anti-collection and anti-search engines.
Disclaimer: I hope you will not remove the copyright of the original author when reprinting it. Thank you for your cooperation.
Due to my limited level of writing and poor writing, please forgive me. If you want to criticize or comment, please add QQ to me.
At present, many people have begun to focus on generating HTML pages on dynamic pages. However, the selection of the HTML generation method and anti-collection method does not prevent the search engine issue, which is often bothering everyone. Solving this problem is the cause of this article.
First, let's talk about several common HTML generation methods:
There are only two steps to generate an HTML method:
1. Obtain the content of the HTML file to be generated
2. Save the obtained HTML file content as an HTML file
Here I will mainly explain the first step: how to obtain the content of the HTML file to be generated:
Currently, the following methods are commonly used to obtain the content of HTML files:
1. Str = "<HTML Tag> content STR = STR & "read content from the content database ........."
This method is similar to writing the HTML content to be generated in the script. It is not convenient to preview the content of the generated page, and the page cannot be visualized. It is more complicated to change the HTML template.
There are many people using this method, but I think this method is the most inconvenient.
2. Create a separate HTML template page. Dynamic Content is marked with specific characters (for example, $ title $ is used as the webpage title) and ADODB is used. stream or scripting. fileSystemObject loads the template content, and then replaces the originally set tag with dynamic content (for example, replace (the loaded template content, "$ title $ ", RS ("title "))).
3. Use XMLHTTP or serverxmlhttp to obtain the HTML content displayed on the dynamic page.
Examples of commonly used HTML file generation:
'--------------- Xiao zhenkai (Xiao Qi)
'Weburl is the dynamic page address to be obtained
'Gethttppage (weburl) is a function for retrieving dynamic page content.
Weburl = "http: //" & request. servervariables ("SERVER_NAME") & "/contact. asp? Id = "& RS (" ID ") &" "'specifies the dynamic page address
Body = gethttppage (weburl) 'Use the function to get the content of the dynamic page address
'--------------- Xiao zhenkai (Xiao Qi)
The biggest advantage of this method is that you do not need to write static template pages, but convert the original dynamic pages to HTML static pages, but the generation speed is not too fast.
I often use 3rd HTML generation methods: Use XMLHTTP to get the HTML content generated by dynamic pages, and use ADODB. Stream or scripting. FileSystemObject to save it as an HTML file.
The second step is to generate the file:
Commonly used files in ASP are ADODB. Stream and scripting. FileSystemObject.
1. Scripting. FileSystemObject file generation method:
Code: [copy to clipboard] '----------------- Xiao zhenkai (Xiao Qi)
Set FSO = Createobject ("scripting. FileSystemObject ")
File = server. mappath ("to generate a file catalog and file name .htm ")
Set TXT = FSO. opentextfile (file, 8, true)
Data1 = "file content" use writeline to generate a file
TXT. writeline data1
Data2 = "file content" 'Use the write method to generate a file
TXT. Write data2
TXT. Close
TXT. FSO
'--------------- Xiao zhenkai (Xiao Qi)
2. file generation method of ADODB. Stream:
Dim objadostream
Set objadostream = server. Createobject ("ADODB. Stream ")
Objadostream. type = 1
Objadostream. open ()
Objadostream. Write ("file content ")
Objadostream. savetofile to generate the file principal and file name .htm, 2
Objadostream. Close ()
'--------------- Xiao zhenkai (Xiao Qi)
Let's talk about some of my experience in HTML anti-collection, but not search engine spider protection:
I have developed several collection programs and studied a lot of collection program code, so I have a little understanding of the principles of the collection program.
Let's talk about the collection principle first:
The main steps of the collection program are as follows:
1. Get the content of the collected page
2. Extract all used data from the retrieved code
1. Get the content of the collected page
ASP is commonly used to obtain the content of collected pages:
1. Use the serverxmlhttp component to obtain data
'--------------- Xiao zhenkai (Xiao Qi)
'Create object
Dim objxmlhttp
Set objxmlhttp = server. Createobject ("msxml2.serverxmlhttp ")
'Request file, in asynchronous form
Objxmlhttp. Open "get", weburl, false
Objxmlhttp. Send
While objxmlhttp. readystate <> 4
Objxmlhttp. waitforresponse 1000
Wend
'Expected result
Getbody = objxmlhttp. responsebody
'Release the object
Set objxmlhttp = nothing
'--------------- Xiao zhenkai (Xiao Qi)
End Function
Call method:
Getbody (File URL)
2. Or XMLHTTP component to get data
Code: [copy to clipboard] function getbody (weburl)
'--------------- Xiao zhenkai (Xiao Qi)
'Create object
Set retrieval = Createobject ("Microsoft. XMLHTTP ")
With Retrieval
. Open "get", weburl, false ,"",""
. Send
Getbody =. responsebody
End
'Release the object
Set retrieval = nothing
'--------------- Xiao zhenkai (Xiao Qi)
End Function
Call method:
Getbody (File URL)
The obtained data content can be used only after encoding and conversion.
Code: [copy to clipboard] function bytestobstr (body, cset)
'--------------- Xiao zhenkai (Xiao Qi)
Dim objstream
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. type = 1
Objstream. mode = 3
Objstream. Open
Objstream. Write body
Objstream. Position = 0
Objstream. type = 2
Objstream. charset = cset
Bytestobstr = objstream. readtext
Objstream. Close
Set objstream = nothing
'--------------- Xiao zhenkai (Xiao Qi)
End Function
Call method: bytestobstr (the data to be converted, encoding) 'encoding is commonly gb2312 and UTF-8
2. Extract all used data from the retrieved code
Currently, I have mastered the following methods:
1. Use the mid function built in ASP to intercept the required data
Code: [copy to clipboard] function body (wstr, start, over)
'--------------- Xiao zhenkai (Xiao Qi)
Start = newstring (wstr, start)
'Set the unique start mark of the data to be processed
Over = newstring (wstr, over)
'Corresponds to start, which is the unique end mark of the data to be processed.
Body = mid (wstr, start, over-start)
'Set the display page range
'--------------- Xiao zhenkai (Xiao Qi)
End Function
Call method: Body (content of the collected page, start mark, end mark)
2. Use regular expressions to obtain the required data
Code: [copy to clipboard] function body (wstr, start, over)
'--------------- Xiao zhenkai (Xiao Qi)
Set Xiaoqi = new Regexp 'to set the configuration object
Xiaoqi. ignorecase = true' case insensitive
Xiaoqi. Global = true' is set to full-text search
Xiaoqi. pattern = "" & start & ". + ?" & Over & "" Regular Expression
Set matches = Xiaoqi. Execute (wstr )'
Set Xiaoqi = nothing
Body = ""
For each match in matches
Body = body & Match. value' loop matching
Next
'--------------- Xiao zhenkai (Xiao Qi)
End Function
Call method: Body (content of the collected page, start mark, end mark)
The idea of the collection program is as follows:
1. Retrieve the address of each page on the page list of the website
Currently, the paging addresses of most dynamic websites have rules, such:
Dynamic page
Page 1: index. asp? Page = 1
Page 2: index. asp? Page = 2
Page 3: index. asp? Page = 3
.....
Static Page
Page 1: page_1.htm
Page 2: page_2.htm
Page 3: page_3.htm
.....
Get the address of each page on the page list page of the website. You only need to replace the variable with the character changed in the address of each page, for example, page _ <% = "& page &" %>. htm
2. Retrieve the page content of the collected website
3. Extract the URL Connection address of the collected content page from the page list Code
There are also fixed rules for content page connections on most pages, such:
<A href = "url1"> connection 1 </a> <br>
<A href = "url2"> connection 2 </a> <br>
<A href = "url3"> connection 3 </a> <br>
Use the following code to obtain a URL Connection set
Code: [copy to clipboard] '----------------- Xiao zhenkai (Xiao Qi)
Set Xiaoqi = new Regexp
Xiaoqi. ignorecase = true
Xiaoqi. Global = true
Xiaoqi. pattern = "". + ?" "
Set matches = Xiaoqi. Execute (page list content)
Set Xiaoqi = nothing
Url = ""
For each match in matches
Url = URL & Match. Value
Next
'--------------- Xiao zhenkai (Xiao Qi)
4. Obtain the content on the collected content page, and extract the data to be obtained from the collected content page according to the "extraction mark ".
Because it is a dynamically generated page, most of the content pages have the same HTML Tag, we can extract the content of each part according to these regular tags.
For example:
Each page has a webpage title. You can use the mid truncation function written above to obtain the value between them, or use a regular expression to obtain the value.
Example: Body ("","")
After introducing the fine principle of the collector, I began to talk about the anti-collection policy.
Currently, there are many anti-collection methods. First, we will introduce the common anti-collection methods and their drawbacks and collection countermeasures:
1. determine the number of times an IP address accesses the website page within a certain period of time. If the access speed is significantly higher than that of normal users, access from this IP address is denied.
Disadvantages:
1. This method is only applicable to dynamic pages, such as ASP, JSP, and PHP. Static pages cannot be used to determine the number of times an IP address has accessed this site.
2. This method will seriously affect the indexing of search engine spider because the indexing speed of search engine spider is faster and multithreading. This method also rejects the search engine spider from indexing site files.
Collection countermeasure: The collection speed can only be slowed down or not collected
Suggestion: Create an IP address library for search engine spider, and only allow search engine spider to quickly browse site content. It is not easy to collect the IP address library of search engine spider. A search engine spider may not have only one fixed IP address.
Comment: This method is effective for data collection prevention, but may affect the search engine's indexing.
2. Use JavaScript to encrypt the content page
Disadvantage: This method is applicable to static pages, but it seriously affects the search engine's indexing status. The content received by the search engine is also encrypted.
Collection countermeasure: It is recommended that you do not collect it. If you need to collect it, you can also collect the JS script for password cracking.
Suggestion: no improvement suggestions currently
Comment: We recommend that you do not use this method for webmasters with search engine traffic.
3. Replace the specific mark on the content page with "specific mark + hidden copyright text"
Disadvantages: This method has minor drawbacks. It only increases the page file size a little bit, but is easy to perform reverse collection.
Collection countermeasure: replace or replace the collected copyrighted text containing the hidden copyrighted text with your own copyright.
Suggestion: no improvement suggestions currently
Comments: I feel that it is of little practical value. Even adding random hidden texts is also a perfect addition.
4. Users can only browse after login
Disadvantages: This method seriously affects search engine spider's indexing
Collection countermeasure: at present, some people have published countermeasure articles. For specific countermeasure, see ASP thief program how to use XMLHTTP to submit forms and send cookies or sessions.
Suggestion: no improvement suggestions currently
Comment: We recommend that you do not use this method for webmasters with search engine traffic. However, this method is somewhat effective in preventing general collection programs.
5. Paging using JavaScript and VBScript scripts
Disadvantages: Search Engine indexing is affected.
Collection countermeasure: Analyze JavaScript and VBScript scripts, find out their paging rules, and create a page set for this site.
Suggestion: no improvement suggestions currently
Comment: anyone who understands the scripting language can find out its paging rules.
6. You can only view the data through the link on this site, for example, request. servervariables ("http_referer ")
Disadvantages: Search Engine indexing is affected.
Collection countermeasure: I don't know if I can simulate the webpage source .... Currently, I have no collection countermeasures for this method.
Suggestion: no improvement suggestions currently
Comment: We recommend that you do not use this method for webmasters with search engine traffic. However, this method is somewhat effective in preventing general collection programs.
As can be seen from the above, the commonly used anti-collection methods will either have a great impact on Search Engine indexing, or the Anti-collection effect is not good, and the anti-collection effect is not effective. Is there any effective method to prevent collection without affecting search engine indexing? Next, let's take a look. The highlights will be presented to you immediately.
The following is my anti-collection policy, which prevents collection and does not prevent search engines.
As you can see from the collection principles mentioned above, most collection programs collect data by analyzing rules, such as analyzing paging file name rules and page Code rules.
I. Countermeasures against collection of paging file name rules
Most collectors Perform Batch and multi-page collection by analyzing paging file name rules. If others cannot find the file name rules for your paging files, they will not be able to perform batch multi-page collection on your website.
Implementation Method:
I think using MD5 to encrypt the paging file name is a good method. Here, someone will say that you use MD5 to encrypt the paging file name, based on this rule, others can simulate your encryption rules to get your paging file name.
I want to point out that when we encrypt the paging file name, we should not only encrypt the changed part of the file name.
If I represents the page number, we should not encrypt it like this
Page_name = MD5 (I, 16) & ". htm"
It is best to add one or more characters to the page number to be encrypted, such as page_name = MD5 (I & "any one or several letters", 16) & ". htm"
Because MD5 cannot be decrypted, and other people will see the results of MD5 encryption, they will not be able to know what the letter you followed up after I, unless he uses brute force *** MD5, it is not realistic.
Ii. Anti-collection countermeasures for page Code rules
If there are no code rules on our content page, no one else can extract the content they need from your code.
Therefore, to prevent data collection in this step, we need to make the Code have no rules.
Implementation Method:
Randomize tags to be extracted by the recipient
1. Customize multiple webpage templates with different important HTML tags in each webpage template. When the page content is displayed, the webpage template is randomly selected. Some pages are displayed in CSS + Div layout, some pages use table layout. This method is troublesome. There are several more template pages for a content page. However, anti-collection is a very cumbersome task, it is worthwhile for many people to prevent data collection.
2. If the above method is too troublesome, you can also randomize the important HTML mark on the webpage.
The more web templates the more HTML code is, the more random the HTML code is. When the other party analyzes the Content Code, the more difficult it is. When the other party specifically writes a collection policy for your website, at this time, the vast majority of people will know how to leave, because this person is just lazy and will collect others' website data ~~~ At present, most people collect data using collection programs developed by others. After all, a few people develop collection programs to collect data.
Some simple ideas are provided to you:
1. display the content that is important to data collectors but not to search engines using client scripts
2. Dividing a page of data into N pages is also a method to increase the difficulty of data collection.
3. Use a deeper connection, because most of the collection programs can only collect the first three layers of website content. if the content is located in a deeper connection layer, you can avoid being collected. However, this may cause inconvenience to the customer.
For example:
Most websites use the homepage-content index page-Content Page
If changed:
Homepage ---- content index page ---- content page entry ---- Content Page
Note: It is best to add the code for automatically transferring in content pages to the content page entry.
As a matter of fact, as long as the first step of anti-collection is done (encryption paging file name rules), the Anti-collection effect is already good. We recommend that you use both anti-collection methods to increase the collection difficulty for the collectors, this makes it difficult for them to return to the website.