Simple ASP Acquisition Code Tutorial _ Thieves/Collection

Source: Internet
Author: User
Collection Start
The first step is to analyze the pages to be collected.
Use the browser to open the page to be collected (such as: http://sports.sina.com.cn/k/2008-09-15/04593948756.shtml, you can other pages), open, click the right button, check the source file.

The second step is to find the location of the content to be collected.
If I were to capture the title and content of this page:
Title in

The content in the!--body content begin--> and!--body content end--> between
Notice the uniqueness of the location, you can find it, use the search in the edit, see if it is the only, as far as possible is the only, if not, as far as possible is the first, if not again, can only replace

Step three, write code

Copy Code code as follows:

<%
' Function: ASP acquisition code
' Author: wangsdong
' Remarks: Support original program, please keep this information, thank you
Url= "Http://sports.sina.com.cn/k/2008-09-15/04593948756.shtml"
Str=gethttppage (URL)
Title=strcut (str, "

Content=strcut (str, "<!--body content begin-->", "<!--body content End-->", 2)
Response.Write "News title <br><b>" &title& "</b><br><br><br> news content:<br> "&content

Function gethttppage (URL)
On Error Resume Next
Dim http
Set Http=server.createobject ("Microsoft.XMLHTTP")
Http.open "Get", Url,false
Http.send ()
If Http.readystate<>4 Then
Exit function
End If
Gethttppage=bytestobstr (Http.responsebody, "GB2312")
Set http=nothing
If Err.number<>0 Then
Response.Write "<p align= ' center ' ><font color= ' red ' ><b> server gets file contents error </b></font></p > "
Err.Clear
End If
End Function

Function Bytestobstr (Body,cset)
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
End Function

' Intercept string, 1. Includes starting and terminating characters, 2. Excluding
Function Strcut (Strcontent,startstr,endstr,cuttype)
Dim STRHTML,S1,S2
strHTML = strcontent
On Error Resume Next
Select Case Cuttype
Case 1
S1 = InStr (STRHTML,STARTSTR)
S2 = InStr (s1,strhtml,endstr) +len (ENDSTR)
Case 2
S1 = InStr (strhtml,startstr) +len (STARTSTR)
S2 = InStr (S1,STRHTML,ENDSTR)
End Select
If ERR Then
Strcute = "<p align= ' center ' > did not find what was needed. </p> "
Err.Clear
Exit Function
Else
Strcut = Mid (STRHTML,S1,S2-S1)
End If
End Function
% >


So it's OK, I'm going to get the content out of it and you can write that to the database so that the data is yours.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.