ASP Sampling code sample

Source: Internet
Author: User
Tags exit end

The following is one side of ASP acquisition page content The most basic prerequisite source code, modify the following code needs to have a certain ASP base.

The following is a reference fragment:
<%
' 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
% >



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.