Use XMLHTTP to increase the stock market query function for the website

Source: Internet
Author: User
Tags format chr comments dns2 final html form query trim
XML under normal circumstances, if we want to understand the stock market, we must log into the professional stock site, enter the company code to see the specific price. In fact, using the XMLHTTP agreement, each of us can be in their own personal website to provide detailed information on the stock market inquiries service, this article describes how to use ASP, VBScript combined with XMLHTTP programming to achieve this function.

First, the principle
The principle is very simple, in many large websites have real-time updated stock market information, we sent through their own web Server XMLHTTP command to visit the Yahoo Financial site of the stock market database server, from the database to query what we need, and then through ASP Group Composite Web page back to the client.
At the same time, we use the XMLHTTP protocol to achieve the client page without refreshing effect and to the server to provide data retrieval requirements.
XMLHTTP allows you to open an HTTP connection to any server, send some data, and retrieve some data. And all of this is done in a few scripts. The XMLHTTP object is typically used for XML data interchange, but data in other formats is also allowed.
In business applications The standard pattern of this type of interchange is that the client sends a text string to the server, and then the server loads the string into a Xmldom object and interprets it, then returns a paragraph of HTML to the client, or another piece of XML code for the client to let the client's browser explain itself. In this way, it is a very effective form of information transfer, especially if you use DHTML to allow you to dynamically display it based on the return information.
The specific process is: The client through XMLHTTP Stock Quotes query Request-->web Server in the ASP listening page to accept the request, use XMLHTTP to the stock market database server send Retrieval command--> database to perform query operations, Return results to our own Web server (HTML form)-->web the server receives the content, filters out the extra parts of the HTML, picks out the pure stock data, combines the results to the client-> the client browser uses VBScript to display it.

Second, ASP XMLHTTP programming Brief
1, Client dns2.htm page:
<script language= "VBScript" >
Sub Submit1_onmouseup
Dim Objxml, objxsl, Objfso,strfile, strFileName, Strxsl,strurl, Thestring,theform
Set theform = Document.wordfind
window.status= "Retrieving Data???"
Strurl= "dns2.asp" Server listening page address
Set Objxml = CreateObject ("Microsoft.XMLHTTP") ' creates the XMLHTTP component of MS
Stra = "submit=submit&fqdn=" &theform.webname.value
Objxml.open "POST", Strurl,false ' using post submission method;
Objxml.setrequestheader "Content-length", Len (stra)
Objxml.setrequestheader "Content-type", "application/x-www-form-urlencoded"
Objxml.send stra ' Send message
Xmlget = Objxml.responsebody ' Wait a moment, get the result of the server-side return;
Xmlget = Bytes2bstr (xmlget) ' Converts a single byte into a text Format function, which can be found in the dns2.asp program below;
Theform.comments.value=xmlget
Set Objxml = Nothing
End Sub
</script>

<body bgcolor= #a1bae6 >
<table border= "0" cellpadding= "0" cellspacing= "0" width= "100%" >
<tr>
&LT;TD width= "100%" align=center>
<form method= "POST" Name=wordfind onsubmit= "Javascript:return false" >
<font color= #002e5b Face=geneva,arial,sans-serif size=2>
<B> Please select Stock name (US Nasdaq) </B></FONT>
<font color= #002e5b Face=geneva,arial,sans-serif size=2><b>:<br>
<select name=webname style= "HEIGHT:22PX; width:80px ">
<option value= "^ixic" > Nasdaq </option><option value= "Asia" > sub-letter </option>
<option value= "China" > Chinese net </option> <option value= "ntes" > NetEase </option>
<option value= "Sina" > Sina net </option> <option value= "SOHU" > Sohu </option>
</select><input type= "Submit" value= "Query" Id=submit1 name=submit1></b>
<textarea name=comments readonly rows=10 cols=76 ></TEXTAREA>
</form></td></tr></table></body>2, server-side dns2.asp program:
<%
Dim xmlget
Xmlget= ""
If Len (Trim (Request.Form ("FQDN))" > 1 Then
Dim Objxml, objxsl, objFSO
Dim strfile, strFileName, strxsl
Dim strURL, TheString

' The Stock market database server address
Strurl= "http://cn.finance.yahoo.com/q?s=" +trim (Request.Form ("FQDN")) + "&d=2b"
Set Objxml = CreateObject ("Microsoft.XMLHTTP") ' creates the XMLHTTP component of MS
Objxml.open "Get", strURL, False
Objxml.send ' Send a message
Xmlget = Objxml.responsebody ' Wait a moment, get the result of the stock market data server end;
Xmlget = Bytes2bstr (xmlget) ' converts to a text Format function that can be found in the source program;

' Filter out useless HTML components and pick out stock specific information;
StrFind1 = InStr (1,xmlget, "last Deal", 1) +8
StrFind2 = InStr (Strfind1,xmlget, "<b>", 1) +3
StrFind3 = InStr (Strfind2,xmlget, "</b></td>", 1)
Xmlget1= "Final transaction:" +mid (Xmlget,strfind2,strfind3-strfind2) +chr +CHR (10) ' final transaction price

StrFind1 = InStr (1,xmlget, "ups and Downs", 1) # +4
StrFind2 = InStr (Strfind1,xmlget, "<font color=", 1) +19
StrFind3 = InStr (Strfind2,xmlget, "</font>", 1)
Xmlget2= "ups and Downs:" +mid (Xmlget,strfind2,strfind3-strfind2) +chr +CHR (10) ' ups and downs

Set Objxml = Nothing
End If
Response.Write Trim (Request.Form ("FQDN")) + "stock Quotes:" +CHR +chr (a) +xmlget1+xmlget2
function Bytes2bstr (VIN)
Strreturn = ""
For i = 1 to LenB (VIN)
Thischarcode = ASCB (MidB (vin,i,1))
If Thischarcode < &am



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.