实例出自落伍者论坛
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='generator' content='默飞冲天'>
<meta name='keywords' content='默飞冲天'>
//niceidea 签名留念 :^
<style type=text/css>body {font-family: Arial; font-size: 12px;color: #000000;}td {font-family: Arial; font-size: 12px;line-height:20px;}a:link,a:visited{text-decoration: none; color: #000000}a:hover { color: #ff0000; text-decoration: underline}</style>
<title>天气预报 - 默飞冲天</title>
</head>
<body>
<%
'制作:默飞
'QQ:33224360
'http://mofei.xinxiu.com
'天气预报最新适用采集程序
'声明取得目标信息的函数,通过XML组件进行实现。
Function GetURL(url)
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "GET", url, False
.Send
GetURL = bytes2bstr(.responsebody)
'对取得信息进行验证,如果信息长度小于100则说明截取失败
if len(.responsebody)<100 then
response.write "获取远程文件 <a href="&url&" target=_blank>"&url&"</a> 失败。"
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, "<table width=""979"" height=""185"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"">")
'搜索要偷取的内容的结束位置
Str_end = instr(Str_start, Html, "<table width=""979"" height=""105"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"">")
'截取内容
Html = Mid(Html, Str_start, Str_end - Str_start)
'调整表格
Html=replace(replace(Html,"width=""979""","width=100%"),"height=""185""","") '大表格
Html=replace(replace(Html,"width=""133""","width=95%"),"height=""183""","") '背景大小
Html=replace(replace(Html,"width=""973""",""),"height=""183""","")
Html=replace(replace(Html,"width=""113""","width=100%"),"height=""35""","") '日期表格
Html=replace(replace(Html,"width=""57""",""),"width=""56""","") '图片表格
Html=replace(replace(Html,"width=""50""",""),"height=""46""","")
Html=replace(replace(Html,"height=""57""",""),"height=""73""","")
Html=replace(Html,"width=""141""","width=14%") '表格分配
Html=replace(Html,"width=""140""","width=14%")
Html=replace(Html,"width=""139""","width=14%")
Html=replace(Html,"width=""133""","width=16%")
Html=replace(Html,"width=""125""","width=100%")
Html=replace(Html,"width=""107""","width=100%")
Html=replace(replace(Html,"../images/","images/"),"./images/","images/") '图片路径
response.write Html
'Response.Write"采集完毕!"
%>
</body>
</html>

订阅我的BLOG(RSS)