西数超哥博客
运维经验教程分享

asp抓取网页内容并展示示例二

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<%Session.CodePage=65001%> 

<%Response.charset = "utf-8"%>

<html>

<head>

</head>

<body>

<% 


Function getHTTPPage(url)

dim objXML

set objXML=createobject("MSXML2.XMLHTTP")'定义

objXML.open "GET",url,false'打开

objXML.send()'发送

If objXML.readystate<>4 then '判断文档是否已经解析完,以做客户端接受返回消息

exit function

End If

getHTTPPage=BytesToBstr(objXML.responseBody)'  返回信息,同时用函数定义编码

set objXML=nothing'关闭

if err.number<>0 then err.Clear

End Function



Function Newstring(wstr,strng)

Newstring=Instr(lcase(wstr),lcase(strng))

if Newstring<=0 then Newstring=Len(wstr)

End Function



Function BytesToBstr(body) 

dim objstream 

set objstream = CreateObject("adodb.stream") 

objstream.Type = 1 

objstream.Mode =3 

objstream.Open 

objstream.Write body 

objstream.Position = 0 

objstream.Type = 2 

objstream.Charset = "UTF-8" 

BytesToBstr = objstream.ReadText 

objstream.Close 

set objstream = nothing 

end Function





url="https://www.ysidc.top/9207.html"

wstr=getHTTPPage(url)



response.write wstr



%> 



<br><br>

</body>

</html>

把代码保存为asp文件,上传到空间,直接访问,即可测试抓取。

赞(1)
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除。本站原创内容未经允许不得转载:西数超哥博客 » asp抓取网页内容并展示示例二