|
Find a stock
In this example we let the user select a stock
and then we display the latest information on another page .
You have to enter a valid stock ticker symbol for this to work
properly . Some examples are sun , msft , yhoo , cnet
Code :
Here is the code for the form
<form action = "stockfind.php"
method="post">
<input type= "text" name = "quote" value="sun">
<br>
<input type = "submit" value = "display stock
quote" name="submit">
</form>
And here is the code for stockfind.php
<%
Dim objXML , strURL , strQuote
'create an instance of the XMLHTTP component
Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
'get what the user entered in the form
strQuote = Request.Form("quote")
'build up the url and store it in strURL variable
strURL ="http://finance.yahoo.com/q?s=" & strQuote
& "&d=v1"
'get the strURL
objXML.Open "GET" , strURL , False ,"",""
'send the information
objXML.Send
'if we have no errors
If Err.Number = 0 Then
'and the url is valid
If objXML.Status = 200 then
strOpen = objXML.ResponseText
'this is the start point on the page that we want
startPoint= InStr( strOpen, "<b>Views: </b>"
)
'and this is the end point on the page
endPoint = InStr( startPoint, strOpen, "Add to My Portfolio</a>")
'store all of the rest in the variable strYahoo
strYahoo = Mid( strOpen, startPoint, endPoint-startPoint )
'display the part of the page we want
response.Write strYahoo
Else
'bad url display a message
Response.Write "Incorrect URL"
End if
Else
'if we do have an error display the description of the error
Response.Write Err.Description
End If
'clear up
Set objXML = Nothing
%>
|