当前位置:于振海网 > 文摘 >

asp抓取网页内容自己显示并实时最新内容

发布时间:2011年11月23日更新时间:2023年6月6日作者:未知文章ID:526浏览:

    以下代码为asp获取https://www.yuzhenhai.com/index.html网页的内容。
    需要注意的是服务器有时读取缓存内容,这样就造成了读取的内容不是最新的。可以在网页地址后面加上日期时间参数,保证获取的内容是最新的。
    html后面加参数不影响html显示,对于GetPage()函数来说,好比是一个新网页,所以是实时抓取,不从缓存读取。

<%
response.write GetPage("https://www.yuzhenhai.com/index.html?time=" & date & "-" & time)

Function GetPage(MyUrl)
dim objXmlHttp
set objXmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
objXmlHttp.open "GET",MyUrl,false
objXmlHttp.send()
GetPage = bBytesToBstr(objXmlHttp.responseBody)
set objXmlHttp = nothing
end Function

Function bBytesToBstr(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 = "GB2312"
bBytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
end Function

%>

顶一下
0
0%
踩一下
0
0%
评论列表 发表评论
推荐文章