我们可以使用vbscript或者asp支持的其他脚本在服务器端对获取的信息进行整理。这些函数都是很常见的,现在把它们拿出来,好像也没有什么用。 1、instr函数 Instr()
FUNCTION: 返回字符或字符串在另一个字符串中第一次出现的位置. SYNTAX: Instr([start, > strToBeSearched, strSearchFor [, compare>)
ARGUMENTS: Start为搜索的起始值,strToBeSearched接受搜索的字符串 strSearchFor要搜索的字符compare 比较方式(详细见ASP常数) EXAMPLE: <%
strText = \"This is a test!!\" pos = Instr(strText, \"a\") response.write pos %>
RESULT: 9 2、instrrev函数 InstrRev()
FUNCTION: 同上,只是从字符串的最后一个搜索起
SYNTAX: InstrRev([start, > strToBeSearched, strSearchFor [, compare>) ARGUMENTS: 同上. EXAMPLE: <%
strText = \"This is a test!!\" pos = InstrRev(strText, \"s\") response.write pos %>
RESULT: 13 3、mid函数 Mid()
FUNCTION: 返回特定长度的字符串(从start开始,长度为length). SYNTAX: Mid(string, start [, length>) ARGUMENTS: EXAMPLE: <%
strTest = \"This is a test! Today is Monday.\" response.write Mid(strTest, 17, 5) %>
RESULT: Today 4、replace Replace()
FUNCTION: Returns a string in which a specified sub- string has been replaced with another substring a specified number of times.
SYNTAX: Replace(strToBeSearched, strSearchFor, strReplaceWith [, start [, count [,
compare>>>)
ARGUMENTS: strToBeSearched is a string expression containing a sub-string to be replaced; strSearchFor is the string expression to search for within strToBeSearched; strReplaceWith is the string expression to replace sub-string strSearchFor; start (optional) is the numeric character position to begin search; count (optional) is a value indicating the comparision constant. EXAMPLE: <%
strTest = \"This is an apple!\"
response.write Replace(strTest, \"apple\ %>
RESULT: This is an orange!
以上的四个函数是在远程获取中用的最多的,比起正则表达式,虽然功能上不足,但是使用他们显得更加简易。 另外一些可能用到的 trim()
FUNCTION: 去掉字符串两边的空格. SYNTAX: Rtrim(string) ARGUMENTS: EXAMPLE: <%
strTest = \" This is a test!! \" response.write RTrim(strTest) %>
RESULT: This is a test!!
还有ltrim和rtrim,分别是去掉字符串左边和右边的空格。StrReverse() FUNCTION: 反排一字符串 SYNTAX: StrReverse(string) ARGUMENTS: EXAMPLE: <%
strTest = \"This is a test!!\"
response.write StrReverse(strTest) %>
RESULT: !!tset a si sihT
例子是落伍者论坛 mofei的文章。
'制作:默飞 'QQ:33224360
'http://mofei.xinxiu.com
'天气预报最新适用采集程序
'声明取得目标信息的函数,通过XML组件进行实现。 Function GetURL(url)
Set Retrieval = CreateObject(\"Microsoft.XMLHTTP\") With Retrieval
.Open \"GET\.Send
GetURL = bytes2bstr(.responsebody)
'对取得信息进行验证,如果信息长度小于100则说明截取失败 if len(.responsebody)<100 then
response.write \"获取远程文件 \"&url&\" 失败。\" response.end end if End With
Set Retrieval = Nothing End Function
' 二进制转字符串,否则会出现乱码的! function bytes2bstr(vin) strreturn = \"\"
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1)) if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode) else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode)) i = i + 1 end if next
bytes2bstr = strreturn end function
'声明截取的格式,从Start开始截取,到Last为结束 Function GetKey(HTML,Start,Last) filearray=split(HTML,Start)
filearray2=split(filearray(1),Last) GetKey=filearray2(0) End Function
Dim Softid,Url,Html,Title
'把下面的[将乐]改成你的城市,就是你城市的天气预报了,可到www.tq121.com.cn里查一下,有没收录你的城市,一般到县级的都有。
Url=\"http://weather.tq121.com.cn/detail.php?city=将乐\" Html = GetURL(Url)
'搜索要偷取的内容的开始位置
Str_start = instr(Html, \"预报发布时间\")
Str_start = instr(Str_start, Html, \"