日期:2009-05-23  浏览次数:20780 次

技术要点:可以对固定的字符串进行截取其中的某一部分,亦可以对某一网页进行页面截取.
安装方法:把上面的文件包下载后,解压后,双击reg.bat即可注册组件.然后把里面的test1.asp,test2.asp,test3.asp拷贝到你的IIS虚拟目录下面.然后通过浏览器浏览(具体的IIS配置等本文略过)

下面介绍里面的方法调用:
getUrl(url)方法
该方法是返回某个网页的内容.参数只有一个.下面看看调用的例子test1.asp:

<%
Dim test,url
Set test = Server.CreateObject("gzNets.echars")
url="http://www.gzNets.com/error.html"
Response.Write test.getUrl(url)
Set test=nothing
%>

上面的例子将返回http://www.gzNets.com/error.html的页面内容

manage方法
manage方法有三种方式,在调用manage方法之前要先对一系列的参数进行传值.

方式一
功能:返回标志1与标志2之间的内容,并且包括标志1与标志2本身.
例如,返回<table与</table>之间的内容,并且包括了标志<table和</table>

参数:

inputStr 传入被截取的字符串(该字符串可以用刚才的getUrl()方法返回的网页内容)

inputTag1 传入标志1
inputTag2 传入标志2
inputType 传入方式0
outPutStr 输出最后截取到的字符串


例子test2.asp:
<%
Dim test,str
Set test = Server.CreateObject("gzNets.echars")
str="这是测试的<table border=1><tr><td>test</td></tr></table>测试"
test.inputStr=str
test.inputTag1="<table"
test.inputTag2="</table>"
test.inputType=0
test.manage
Response.Write test.outPutStr &"<br>"
test.inputStr=str
test.inputTag1="<td"
test.inputTag2="</td>"
test.inputType=0
test.manage
Response.Write test.outPutStr &"<br>"
Set test=nothing
%>


方式二
功能:返回标志1与标志2之间的内容,但不包括标志1与标志2本身.
例如,返回<table与</table>之间的内容,但不包括了标志<table和</table>

参数:

inputStr 传入被截取的字符串(该字符串可以用刚才的getUrl()方法返回的网页内容)
inputTag1 传入标志1
inputTag2 传入标志2
inputType 传入方式1(注意这里的传入方式必须改成1)
outPutStr 输出最后截取到的字符串

例子可以自己修改一下test2.asp,把里面的inputType改成1看看效果~~~:

方式三
功能:要理解这个功能比较困难.我们通过一些例子来说明吧.
例如,字符串str="这是测试的<table border=1><tr><td>test</td></tr></table>测试",我们可以通过查找"<tr>",因为"<tr>"只有一个(当然其它也有唯一的标志),然后再查找"<tr>"前面的"<".然后设置尾部标志.我们可以通过查找"</tr>",然后查找"</tr>"后面的">".这样首位置和尾位置都确定了.

参数:

inputStr 传入被截取的字符串(该字符串可以用刚才的getUrl()方法返回的网页内容)
inputTag1 传入标志1 例如上面说的"<tr>"
inputPos1 传入向右搜索,还是向左搜索.有两个值:+表示向右 -表示向左
inputTag1Tag 传向标志1的参考标志.就是要向右向左搜索的标志.例如上面说的"<"
inputNum1 传入搜索标志1的右或左边的第几个inputTag1Tag
inputTag2 传入标志2 例如上面说的"</tr>"
inputPos2 传入向右搜索,还是向左搜索.有两个值:+表示向右 -表示向左
inputTag2Tag 传向标志1的参考标志.就是要向右向左搜索的标志.例如上面说的">"
inputNum2 传入搜索标志2的右或左边的第几个inputTag2Tag
inputType 传入方式2(注意这里的传入方式必须改成21)
outPutStr 输出最后截取到的字符串

例子test3.asp:
目的:我们将取出蓝色理想(www.blueidea.com)首页底部的"关于站点 | 广告服务 | 联系站长 | 版权隐私 | 友情链接 | 投稿热线 | 网站地图"内容
<%
Dim test,url
Set test = Server.CreateObject("gzNets.echars")
url="http://www.blueidea.com/index.asp"
test.inputStr=test.getUrl(url)
test.inputTag1="关于站点"
test.inputNum1=1'表示是只有一个
test.inputPos1="-"'表示是向左搜索
test.inputTag1Tag="<table"'标志1的参考标志
test.inputTag2="版权所有"
test.inputNum2=1
test.inputPos2="+"'表示向前
test.inputTag2Tag="</table>"
test.inputType=2
test.manage
Response.Write test.outPutStr
Set test=nothing
%>