asp下利用XMLHTTP 從其他頁面獲取數(shù)據(jù)的代碼
更新時間:2007年11月24日 22:01:59 作者:
利用XMLHTTP 從其他頁面獲取數(shù)據(jù)
我們在編寫ASP代碼的時候,大家都知道可以通過post或者get獲得form表單的數(shù)據(jù),那么我們?nèi)绾沃苯荧@得其他頁面上的數(shù)據(jù)呢?這就要借助xmlhttp協(xié)議了。xmlhttp是xmldom技術(shù)的一部分。
下面的代碼就是一個很簡單的例子,我們利用xmlhttp技術(shù),把http://www.xxxx.com/站點(diǎn)首頁的代碼以xml的形式完全獲取,并且在頁面中輸出。
<%
Dim objXMLHTTP, xml
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://www.codetoad.com/", False
' Pull the data from the web page
xml.Send
Response.write "Here's the html we now have in our xml object"
Response.write "<BR><BR><BR>"
Response.Write "<xmp>"
Response.Write xml.responseText
Response.Write "</xmp>"
Response.write "<BR><BR><BR>"
Response.write " Now here's how the page looks:<BR><BR>"
Response.Write xml.responseText
Set xml = Nothing
%>
下面是另一個實(shí)例
<%
dim objHTTP , objXML , objXSL
set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.open "GET", "http://p.moreover.com/cgi-local/page?c=Pop%20music%20reviews&o=xml", false
objHTTP.send
set objXML = objHTTP.responseXML
set objXSL=Server.CreateObject("microsoft.xmldom")
objXSL.async=false
objXSL.load(Server.MapPath("style.xsl"))
if (objXSL.parseError.errorCode = 0) then
Response.Write(objXML.transformnode(objXSL))
else
Response.Write "Error: " & objXSL.parseError.reason & " URL:" & objXSL.url
end if
Set objHTTP = Nothing
Set objXML = Nothing
Set objXSL = Nothing
%>
style.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<TITLE>moreover...</TITLE>
</head>
<body BGCOLOR="ffffff">
<DIV ALIGN="center">
<TABLE BGCOLOR="ffffff" BORDER="0" CELLPADDING="4" CELLSPACING="0" WIDTH="100%">
<xsl:for-each select="moreovernews/article">
<TR VALIGN="middle">
<TD ALIGN="left" BGCOLOR="ffffff">
<xsl:attribute name="HREF">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:attribute name="TARGET">
_blank
</xsl:attribute>
<xsl:value-of select="headline_text"/>
<xsl:attribute name="HREF">
<xsl:value-of select="document_url"/>
</xsl:attribute>
<xsl:attribute name="TARGET">
_blank
</xsl:attribute>
<xsl:value-of select="source"/>
<xsl:attribute name="HREF">
<xsl:value-of select="access_registration"/>
</xsl:attribute>
<xsl:attribute name="TARGET">
_blank
</xsl:attribute>
<xsl:value-of select="access_status"/>
<xsl:value-of select="harvest_time"/> GMT
</TD>
</TR>
</xsl:for-each>
</TABLE>
</DIV>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我們在編寫ASP代碼的時候,大家都知道可以通過post或者get獲得form表單的數(shù)據(jù),那么我們?nèi)绾沃苯荧@得其他頁面上的數(shù)據(jù)呢?這就要借助xmlhttp協(xié)議了。xmlhttp是xmldom技術(shù)的一部分。
下面的代碼就是一個很簡單的例子,我們利用xmlhttp技術(shù),把http://www.xxxx.com/站點(diǎn)首頁的代碼以xml的形式完全獲取,并且在頁面中輸出。
<%
Dim objXMLHTTP, xml
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://www.codetoad.com/", False
' Pull the data from the web page
xml.Send
Response.write "Here's the html we now have in our xml object"
Response.write "<BR><BR><BR>"
Response.Write "<xmp>"
Response.Write xml.responseText
Response.Write "</xmp>"
Response.write "<BR><BR><BR>"
Response.write " Now here's how the page looks:<BR><BR>"
Response.Write xml.responseText
Set xml = Nothing
%>
下面是另一個實(shí)例
<%
dim objHTTP , objXML , objXSL
set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.open "GET", "http://p.moreover.com/cgi-local/page?c=Pop%20music%20reviews&o=xml", false
objHTTP.send
set objXML = objHTTP.responseXML
set objXSL=Server.CreateObject("microsoft.xmldom")
objXSL.async=false
objXSL.load(Server.MapPath("style.xsl"))
if (objXSL.parseError.errorCode = 0) then
Response.Write(objXML.transformnode(objXSL))
else
Response.Write "Error: " & objXSL.parseError.reason & " URL:" & objXSL.url
end if
Set objHTTP = Nothing
Set objXML = Nothing
Set objXSL = Nothing
%>
style.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<TITLE>moreover...</TITLE>
</head>
<body BGCOLOR="ffffff">
<DIV ALIGN="center">
<TABLE BGCOLOR="ffffff" BORDER="0" CELLPADDING="4" CELLSPACING="0" WIDTH="100%">
<xsl:for-each select="moreovernews/article">
<TR VALIGN="middle">
<TD ALIGN="left" BGCOLOR="ffffff">
<xsl:attribute name="HREF">
<xsl:value-of select="url"/>
</xsl:attribute>
<xsl:attribute name="TARGET">
_blank
</xsl:attribute>
<xsl:value-of select="headline_text"/>
<xsl:attribute name="HREF">
<xsl:value-of select="document_url"/>
</xsl:attribute>
<xsl:attribute name="TARGET">
_blank
</xsl:attribute>
<xsl:value-of select="source"/>
<xsl:attribute name="HREF">
<xsl:value-of select="access_registration"/>
</xsl:attribute>
<xsl:attribute name="TARGET">
_blank
</xsl:attribute>
<xsl:value-of select="access_status"/>
<xsl:value-of select="harvest_time"/> GMT
</TD>
</TR>
</xsl:for-each>
</TABLE>
</DIV>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
相關(guān)文章
實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序
實(shí)例講解實(shí)現(xiàn)抓取網(wǎng)上房產(chǎn)信息的ASP程序...2007-03-03
Asp定時執(zhí)行操作 Asp定時讀取數(shù)據(jù)庫(網(wǎng)頁定時操作詳解)
由于目前部分網(wǎng)頁語言的限制,在定時操作上有一定的困難,但是經(jīng)過我多次的求證,發(fā)現(xiàn)第四種方法無疑是效果最好的,最省心的。2009-10-10
使用xmlHttp結(jié)合ASP實(shí)現(xiàn)網(wǎng)頁的異步調(diào)用
使用xmlHttp結(jié)合ASP實(shí)現(xiàn)網(wǎng)頁的異步調(diào)用...2006-06-06

