简单的GET方式和POST方式抓取内容的例子

<%
Dim Url,Content,awbno
Url = "http://www.fkdex.com/"
awbno = Request.Form("awbno")
If awbno="" Or IsNull(awbno) Then
Content = GetData(Url,1)
Else
Content = PostData(Url&"return.asp","awbno=" & awbno,1)
End If

Content = Replace(Content,"images/",Url & "images/")
Content = Replace(Content,"return.asp","")
Response.Write Content

Function GetData(GetUrl,GetMode)
Dim Http
Set Http = Server.CreateObject("msxml2.XMLHTTP")
With Http
.Open "GET",GetUrl,False
.SetRequestHeader "Referer",GetUrl
.Send
If GetMode = 0 Then
GetData = .ResponseBody
Else
GetData = BytesToBstr(.ResponseBody,"GB2312")
End If
End With
Set Http = Nothing
End Function

Function PostData(PostUrl,PostStr,PostMode)
Dim Http
Set Http = Server.CreateObject("msxml2.XMLHTTP")
With Http
.Open "POST",PostUrl,False
.SetRequestHeader "Content-Length",Len(PostStr)
.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
.SetRequestHeader "Referer",PostUrl
.Send PostStr
If PostMode=0 Then
PostData = .ResponseBody
Else
PostData = BytesToBstr(.ResponseBody,"GB2312")
End If
End With
Set Http = Nothing
End Function

Function BytesToBstr(Body,Cset)
Dim ADOS
Set ADOS = Server.CreateObject("Adodb.Stream")
With ADOS
.Type = 1
.Mode =3
.Open
.Write Body
.Position = 0
.Type = 2
.Charset = Cset
BytesToBstr = .ReadText
.Close
End With
Set ADOS = Nothing
End Function
%>

    相关文章

评论

发表新评论

此内容将保密,不会被其他人看见。
点击刷新验证码
  • 可用的 UBB 标签:
  • 留言最长字数:1000。