古詩詞大全網 - 四字成語 - ASP提取網頁中鏈接和標題的代碼

ASP提取網頁中鏈接和標題的代碼

可以用正則式來做。

自己鉆研吧

Call newsSina

Sub newsSina

dim Content,url,ShowContent

url="/news1000/index.shtml";

Content=GetNewsContent(url)

set re=new RegExp

're.pattern="\[.*?\)"

re.pattern="<li>.*"

re.Global=true

re.IgnoreCase=true

set matches=re.execute(Content)

For Each Match in matches

'ShowContent=ShowContent&right(match.Value,len(match.value)-4)&"<br>"

ShowContent=ShowContent&ChangeURL(right(match.Value,len(match.value)-4))&"<br>"

next

ShowContent=ShowContent&"<br><a href=# onclick=vbscript:history.back>返回首頁</a>"

response.write "<font size=2>"&ShowContent&"</font>"

'str=/m/2005-04-11/110673.html

'str="[財經] <a href=/g/20050411/11251505530.shtml target=_blank>CCTV經濟半小時:黃河還能活幾年</a><FONT class=rq> (2005/04/11 11:25)"

'response.write ChangeURL(str)

End Sub

Function ChangeURL(str)

'response.write str&"<br>"

set Rep=new regExp

Rep.pattern="/news1000/index.shtml";,false

objHttp.open "get",URL,false

objHttp.send()

GetNewsContent=B2B(objHttp.responsebody)

End Function

Function B2B(body)

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="gb2312"

B2B=objStream.ReadText

set objStream=nothing

End Function

%>

主要的是server.createobject("Microsoft.XMLHttp")這個組件

如果要提取更復雜的內容,還要用到正則表達式等。