asp远程获取链接并检测是否是正常网页
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("*.mdb")
exec="select * from 表名"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
Function getHTTPPage(url)
dim objXML
set objXML=createobject("MSXML2.SERVERXMLHTTP.3.0") '调用XMLHTTP组件,测试空间是否支持XMLHTTP
objXML.open "GET",url,false 'false表示以同步的方式获取网页代码,了解什么是同步?什么是异步?
objXML.send() '发送
getHTTPPage=bBytesToBstr(objXML.responseBody)'返回信息,同时用函数定义编码
set objXML=nothing'关闭
End Function
Function bBytesToBstr(body)
dim objstream
set objstream = CreateObject("adodb.stream") '//调用adodb.stream组件
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "utf-8" '转换原来默认的UTF-8编码转换成GB2312编码,否则直接用XMLHTTP调用有中文字符的网页得到的将是乱码
bBytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
end Function
Function GetKey(HTML,Start,Last)
shuju1=instr(HTML,Start)
if shuju1>0 then
filearray=split(HTML,Start)
filearray2=split(filearray(1),Last)
GetKey=filearray2(0)
else
shuju1=0
end if
End Function
Function GetKey2(HTML2,Start2,Last2)
shuju2=instr(HTML2,Start2)
if shuju2>0 then
filearray2=split(HTML2,Start2)
filearray3=split(filearray2(1),Last2)
GetKey2=filearray3(0)
else
shuju2=0
end if
End Function
'开始循环输出网址
if rs.recordcount<>0 then
rs.pagesize=5
page=request("page")
if page<>"" then page=int(page) '把字符型转换为整数型
if page="" then page=1
if page<=0 then page=1
zys=rs.pagecount '确定总页数
if page>zys then page=zys '这一句不要也行
rs.AbsolutePage=page
response.Write "<table class='stdtable stdtablecb' style='font-size: 1.2em;'><thead><tr><th align='center' valign='middle'>序号</th> <th align='center' valign='middle'>ID</th> <th align='center' valign='middle'>店铺网址</th><th align='center' valign='middle'>打开网页</th><th align='center' valign='middle'>检测结果</th><th align='center' valign='middle'>操作</th></tr></thead>"
y=0
for i=1 to rs.pagesize
if rs.eof then
exit for
end if
url=rs("xh") '正常页面 album__space
if Instr(url, "yupoo")>0 then
'url="http://x.yupoo.com/photos/xy6688/albums" '页面暂时被冻结,主页在帐号解冻后可打开
'url="http://x.yupoo.com/photos/99watch/albums" '页面未找到,可能已消失在宇宙中……
'url="http://x.yupoo.com/photos/05940955/albums" '该用户主页暂时关闭
'url="http://baidu.com"
wstr=getHTTPPage(url) '//获取源代码的函数
'response.Write wstr '//输出HTML格式的网页内容
response.Write "<tbody><tr><td align='center' valign='middle'>"&i&"</td><td align='center' valign='middle'>"&rs("ID")&"</td><td align='center' valign='middle'><a href='"&url&"' target='_blank'>"&url&"</a></td> <td align='center' valign='middle'><a href='"&url&"' target='_blank'>《跳转》</a></td> " '//输出HTML格式的网页内容
if wstr<>"" then
huoqu1=GetKey(wstr,"album__s","ce") '页面未找到,可能已消失在宇宙中…… --可能已消失
if huoqu1="pa" then
response.Write "<td align='center' valign='middle'><span style='color:green; margin-left:50px;'>检测正常</span></td><td align='center' valign='middle'><a href='del_wjj.asp?lx=shangjia&id="&rs("ID")&"' >删除</a></td></tr></tbody>"
y=y+1
elseif huoqu1="" then
response.Write "<td align='center' valign='middle'><span style='color:red; margin-left:50px;'>无效域名</span></td><td align='center' valign='middle'><a href='del_wjj.asp?lx=shangjia&id="&rs("ID")&"' >删除</a></td></tr></tbody>"
end if
end if
else
response.Write "<tr><td align='center' valign='middle'>"&i&"</td><td align='center' valign='middle'>"&rs("ID")&"</td><td align='center' valign='middle'><a href='"&url&"' target='_blank'>"&url&"</a></td><td align='center' valign='middle'><a href='"&url&"' target='_blank'>《跳转》</a></td><td align='left' valign='middle'><span style='color:red;margin-left:50px;'>非yupoo网址</span></td><td align='center' valign='middle'><a href='del_wjj.asp?lx=shangjia&id="&rs("ID")&"' target='_blank'>删除</a></td></tr></tbody>" '//输出HTML格式的网页内容
end if
rs.movenext
next
end if
response.Write "<tfoot><tr><th align='center' valign='middle'>序号</th><th align='center' valign='middle'>ID</th> <th align='center' valign='middle'>店铺网址</th><th align='center' valign='middle'>打开网页</th><th align='center' valign='middle'>检测结果</th><th align='center' valign='middle'>操作</th></tr></tfoot>"
response.Write "</table>"
response.Write "<br />检测正常的商家有; "&y&"个"
%>
<ul class="pagination">
<%'数字分页
if zys<=5 then
ks=1
js=zys
end if
if zys>5 and page-2<=0 then
ks=1
js=5'第一次显示10个
end if
if zys>5 and page-2>0 and page+2<=zys then
ks=page-2' 左边显示5个
js=page+3' 左边显示5个
end if
if zys>5 and page-2>0 and page+2>zys then
js=zys
ks=js-4
end if
%>
<li class="first"><a href="?page=1" class="disable">«</a></li><!--跳转到首页-->
<%if page>1 then%>
<li class="previous"><a href="?leixing=<%=request("leixing")%>&yuyue=<%=request("yuyue")%>&page=<%=page-1%>" class="disable">‹</a>
<%end if%></li><!--如果页面大于1则显示上一页-->
<%
for j=ks to js
%>
<%if j=page then%>
<li><a style="background-color: antiquewhite;"><%=j%></a></li><!--当前页面-->
<%else%>
<li><a href="?page=<%=j%>" class="fenye"><%=j%></a></li><!--数字分页有连接-->
<%end if
%>
<%next%>
<%if page<zys then%>
<li class="next"><a href="?leixing=<%=request("leixing")%>&yuyue=<%=request("yuyue")%>&page=<%=page+1%>">›</a></li><!--如果当前页数小于总页数则出现下一页-->
<%end if%>
<li class="last"><a href="?leixing=<%=request("leixing")%>&yuyue=<%=request("yuyue")%>&page=<%=zys%>"> »</a></li><!--尾页-->
<li><a style="background-color: antiquewhite;">共<%=zys%>页,<%=rs.recordcount%>条记录</a></li>
</ul>
版权声明:若无特殊注明,本文皆为《
傲世零零 》原创,转载请保留文章出处。
本文链接:asp远程获取链接并检测是否是正常网页 http://www.wangjunjiang.com/?post=96
正文到此结束