asp截取网页中部分字符的代码。以截取title之间的字符为例子。希望大家能够举一反三!有问题请留言转帖请标注:“来自www.u3u3.com.cn”字样
1、新建一个填URL的文件。我这里用“index.asp”(你可以根据需要改成其他)。其全部代码如下:
<HTML>
<HEAD>
<title>Get URL Text</title>
</HEAD>
<BODY>
<!-- Author: www.u3u3.com.cn -->
<form action="URLGetMSINet.asp">
<table border=0>
<tr><td>URL</td><td><input type=text name=txtURL value=""></td></tr>
</table>
<input type=submit value="Get Text">
</form>
</BODY>
</HTML>
2、再新建一个asp文件。文件名称为:“URLGetMSInet.asp”。此文件名要与上页代码中<form action="URLGetMSINet.asp"> 的引号内的文件名保持一致!!此文件全代码如下:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<title>Get URL Text</title>
</HEAD>
<BODY>
<!-- Author: www.u3u3.com.cn -->
<%
'Set obj = CreateObject("InetCtls.Inet")
Set obj = Server.CreateObject("InetCtls.Inet.1")
obj.RequestTimeOut=20
sRequest = trim(Request("txtURL"))
sText = obj.OpenURL (CStr(sRequest))
sText = "<pre>" & vbcrlf & Server.HTMLEncode(sText) & vbCRLF & "</pre>"
'======='下标越界: '[number: 1]'=数据为空!
'使用split()函数不能有“<”或“>”字符
dim filearray,filearray2
start_u3=cstr("<title>")
end_u3=cstr("</title>")
filearray=split(sText,start_u3)
if filearray(1)=empty then
sText="Sorry! Server Error! u3u3"
else
filearray2=split(filearray(1),end_u3)
sText=filearray2(0)
end if
response.Write(sText)
set obj = nothing
%>
</BODY>
</HTML>
3、测试代码:把这俩文件放到你的web站上。然后在IE中输入:“http://你的web站的URL/index.asp”。回车
出现
在URL后的框内输入一个网站地址。如:“http://www.baidu.com”记得要有“http;//”头。
回车后,出现“百度一下,你就知道 ”。这就是说你成功截取了百度网站首页的<title></title>之间网站标题!
希望大家能够举一反三!有问题请留言转帖请标注:“来自www.u3u3.com.cn”字样。