手机
当前位置:查字典教程网 >编程开发 >ASP教程 >asp中利用xmlhttp抓取网页内容的代码
asp中利用xmlhttp抓取网页内容的代码
摘要:需要分件html源代码此例中的被抓取的html源代码如下2004年8月24日星期二;白天:晴有时多云南风3—4级;夜间:晴南风3—4级;气温...

需要分件html源代码

此例中的被抓取的html源代码如下

<p align=left>2004年8月24日星期二;白天:晴有时多云南风3—4级;夜间:晴南风3—4级;气温:最高29℃最低19℃ </p>

而程序中是从

以2004年8月24日为关键字搜索,直到</p>结速

而抓取的内容就变成了"2004年8月24日星期二;白天:晴有时多云南风3—4级;夜间:晴南风3—4级;气温:最高29℃最低19℃ "

干干净净的了。记录一下。

复制代码 代码如下:

<%

On Error Resume Next

Server.ScriptTimeOut=9999999

Function getHTTPPage(Path)

t = GetBody(Path)

getHTTPPage=BytesToBstr(t,"GB2312")

End function

Function GetBody(url)

on error resume next

Set Retrieval = CreateObject("Microsoft.XMLHTTP")

With Retrieval

.Open "Get", url, False, "", ""

.Send

GetBody = .ResponseBody

End With

Set Retrieval = Nothing

End Function

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 Newstring(wstr,strng)

Newstring=Instr(lcase(wstr),lcase(strng))

if Newstring<=0 then Newstring=Len(wstr)

End Function

%>

<html>

<BODY bgColor=#ffffff leftMargin=0 topMargin=0 MARGINHEIGHT=0 MARGINWIDTH=0>

<>

<%

Dim wstr,str,url,start,over,dtime

dtime=Year(Date)&"年"&Month(Date)&"月"&Day(Date)&"日"

url="http://www.jb51.net/"

wstr=getHTTPPage(url)

start=Newstring(wstr,dtime)

over=Newstring(wstr,"</p>")

body=mid(wstr,start,over-start)

response.write "<MARQUEE onmouseover=this.stop(); onmouseout=this.start();>"&body&"</marquee>"

%>

<>

</body></html>

【asp中利用xmlhttp抓取网页内容的代码】相关文章:

DreamWeaver编写ASP时如何修改代码?

asp获取当前URL代码

asp中FSO复制文件代码

asp中 select top 问题!~

asp 中常用的文件处理函数

asp防止刷新功能实现代码

用xmlhttp编写web采集程序

用asp实现的数据库中存取文件的代码

在ASP中利用ADO显示Excel文件内容的函数

ASP下实现自动采集程序及入库的代码

精品推荐
分类导航