Use XMLHTTP to retrieve data from other pages

Source: Internet
Author: User

When we compile ASP code, we all know that we can use post or get to get form data. How can we directly obtain data on other pages? This requires the help of the XMLHTTP protocol. XMLHTTP is part of xmldom technology.

The following code is a simple example. We use XMLHTTP technology to retrieve the code on the first page of http://www.codetoad.com/site in XML format and output it on the page.

<%
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>"
Response. Write "<XMP>"
Response. write XML. responsetext
Response. Write "</XMP>"
Response. Write "<br>"
Response. Write "Now here's how the page looks: <br>"
Response. write XML. responsetext
 
Set xml = nothing
%>

Next is another instance.

<%
Dim objhttp, objxml, objxsl
Set objhttp = server. Createobject ("Microsoft. XMLHTTP ")
Objhttp. Open "get", "http://p.moreover.com/cgi-local/page? C = pop % 20 music % 20 reviews & 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>

Author's blog:Http://blog.csdn.net/qieyj/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.