<%
on error resume next
'常用函数
'1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
function getHTTPPage(url)
dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"big5")
set http=nothing
if err.number<>0 then err.Clear
end function
'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Function GetKey(HTML,Start,Last)
filearray=split(HTML,Start)
filearray2=split(filearray(1),Last)
GetKey=filearray2(0)
End Function
Url="http://hk.finance.yahoo.com/currency"
Html = getHTTPPage(Url)
'获取指定页面的全部数据
start=Instr(html,"low_content")
'这里设置需要处理的数据的头部,这个变量应视不同情况而设置,具体内容可以通过查看需要抓取的页面的源代码来确定。
'因为在这个程序里我们需要抓取整个页面,所以设置为页面全部抓取。注意,设置的内容必须是页面内容唯一的,不可以重复。
over=Instr(html,"http://au.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif")
'和start相对应的就是需要处理的数据的尾部,同样的,设置的内容必须是页面中唯一的。
body=mid(html,start+257,over-start-400)
''替换界面中的HTML代码
body=replace(body,"class=""yfnc_datamodoutline1"" width=""100%"" cellpadding=""0"" cellspacing=""0""","width=""100%"" cellpadding=""0"" cellspacing=""1"" bgcolor=#CCCCCC")
body=replace(body,"q?s=","huilv/huilvprice.php?s=")
body=replace(body,"=X"">","=X"" target=""_blank"">")
body=replace(body,"HKDCNY","#####")
body=replace(body,"CNYHKD","@@@@@")
body=replace(body,"HKD","CNY")
body=replace(body,"#####","CNYHKD")
body=replace(body,"@@@@@","CNYHKD")
'huilv=GetKey(temp,"#pkvs#","#kws#")
%>