It has been so popular recently that I don’t like collecting, but I am very interested in researching the principles of collection. I got common functions for collection online, studied them, and practiced them in practice. The result was successful. Putting aside the efficiency issue, the collection principle is not complicated. You can enter "acquisition" in the search bar to view its principles. Here is an example of collection:
The code copy is as follows:
<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>
<%Response.CodePage=65001%>
<%Response.Charset="UTF-8"%>
<%Server.Scripttimeout=99999999
response.expires=0
response.expiresabsolute=Now()-1
response.addHeader"pragma","no-cache"
response.addHeader"cache-control","private"
Response.CacheControl="no-cache"
%>
<%
'Declare the function to obtain the target information and implement it through XML components.
FunctionGetURL(url)
SetRetrieval=server.createobject("MSXML2.XMLHTTP")
WithRetrieval
.Open"GET",url,False
.Send
If.Status<>200then' determines whether the document has been parsed to make the client accept the return message
exitfunction
EndIf
'Binary to string
GetURL=sTb(.responsebody)
endwith
'Verify the obtained information. If the information length is less than 100, it means that the interception failed
EndFunction
'Turn binary to string, otherwise garbled will appear!
FunctionsTb(vin)
ConstadTypeText=2
DimBytesStream,StringReturn
SetBytesStream=Server.CreateObject("ADODB.Stream")
WithBytesStream
.Type=adTypeText
.Open
.WriteTextvin
.Position=0
.Charset="GB2312"
.Position=2
StringReturn=.ReadText
.Close
EndWith
SetBytesStream=Nothing
sTb=StringReturn
EndFunction
FunctionNewstring(Wstr,Strng)
Newsstring=Instr(Lcase(Wstr),Lcase(Strng))
IfNewstring<=0ThenNewstring=Len(Wstr)
EndFunction
'Declare the intercepted format, start from Start and end from Over
FunctionGetKey(HTML,Start,Over)
Start=Newstring(HTML, start)
Over=Newstring(HTML,Over)
GetKey=Mid(HTML,Start,Over-start)
EndFunction
DimSoftid, Url, Html, Title
'Collection of Baidu knows
Fori=1to100
Url="http://zhidao.baidu.com/question/10000"&i&".html"
Html=GetURL(Url)
Question=GetKey(Html,"<cq>","</cq>")
Answer=GetKey(Html,"<ca>","</ca>")
Response.Write(Question&"<br/>")