发布ASP记录20140828

本文介绍如何使用ASP技术抓取网页内容,并提供解决中文乱码的方法。此外还介绍了异常处理、正则表达式的应用及字符串替换技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.使用asp下载其他网页使用的函数:

function gethttppage(url)
dim adxmlhttp
set adxmlhttp = server.createobject("microsoft.xmlhttp")
adxmlhttp.open "get",url,false
adxmlhttp.send()
if adxmlhttp.readystate <> 4 then exit function
gethttppage = bytes2bstr(adxmlhttp.responsebody)
set adxmlhttp = nothing
End function


function bytes2bstr(vin)
dim bytesstream,stringreturn
set bytesstream = server.CreateObject("adodb.stream")
bytesstream.type = 2
bytesstream.open
bytesstream.writeText vin
bytesstream.position = 0
'bytesstream.charset = "gb2312"
bytesstream.charset = "utf-8"
bytesstream.position = 2
stringreturn = bytesstream.readtext
bytesstream.close
set bytesstream = nothing
bytes2bstr = stringreturn
end function

2.解决现实的网站中文乱码的问题:

例如采用GBK编码,就在文件的最上面加上 <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 

参考资料:http://www.cnblogs.com/net2/archive/2010/09/08/1821768.html

尝试指定IIS按什么编码读取。 
<%@ codepage=65001%>UTF-8 
<%@ codepage=936%>简体中文 
<%@ codepage=950%>繁体中文 
<%@ codepage=437 %>美国/加拿大英语 
<%@ codepage=932 %>日文 
<%@ codepage=949 %>韩文 
<%@ codepage=866 %>俄文 
codepage指定了IIS按什么编码读取。 
例如采用UTF-8编码,就在文件的最上面加上 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 


3.设置asp异常显示到页面上:

%windir%\system32\inetsrv\appcmd set config -section:asp -scriptErrorSentToBrowser:true 
参考资料:http://www.jb51.net/article/21927.htm


4.asp中使用正则表达式

4.1通用流程:

regex的属性:  test,replace,match

Function RegExpTest(patrn, strng)
Dim regEx, retVal ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = False ' 设置是否区分大小写。
retVal = regEx.Test(strng) ' 执行搜索测试。
If retVal Then
RegExpTest = "找到一个或多个匹配。"
Else
RegExpTest = "未找到匹配。"
End If
End Function 

参考资料:http://webcenter.hit.edu.cn/articles/2010/06-06/06173737.htm


4.2 matches的属性

4.2.1 循环遍历 

for each match in matches

match.firstindex&match.value


4.2.2 matches的属性

(1).Matches对象 是否匹配到

使用Count属性,若>0则表示匹配到了

(2).SubMatches 提取要匹配字符串的关键属性,为一数组

若提取的部分(挎号所挎的部分)为一个,则取索引0,例如

  1. matches(0).SubMatches(0)  

4.3 处理正则表达式中的中文

使用unicode即可;

将中文转化为unicode,放入表达式中。


5.asp中replace函数的使用

url=replace(url,string1,string2)  

string1:source string;string2: string to replace the source

eg:

url = replace(url,"http","")


6.for循环使用


for each i in numbers

...

next


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值