Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get a single stock quote 1

Status
Not open for further replies.

Inspin

Technical User
Joined
Dec 17, 2002
Messages
6
Location
US
Im trying to find a script out there that will allow me to get a single stock quote (meaning I do not want the users entering anything). I've done some research and found that most likely the script would be pulling the data from yahoo.finance.com If anyone has any leads that would be great.


thanks,
Ins
 
Ok, I have now typed this post tnhree times because I keep refreshing the wrong page :P

Basically you may be able to use the XMLHTTP object to get the text source for the page and save it into a string variable. Once you do that it is nly a matter of using the mid function and the instr function to locate the relevant dta and pull it out. There used to be a yahoo weather example floating around but I can't seem to find an exasmple of it on my servers. One word of warning, yahoo seems to be pretty anti-scraping these days and has institued random, strange comments throughout some of their pages as well as lots of copyright statements (the weather one directs you to noaa pages as a public domain source for weather).

Here is an example I just wrote:
Code:
<%
Option Explicit

'If you need to load the page from a remote address, the top portion will handle that
	Response.Buffer = True
	Dim objXMLHTTP, URL

	' Create an xmlhttp object:
	Set objXMLHTTP = Server.CreateObject(&quot;Microsoft.XMLHTTP&quot;)

	URL = &quot;[URL unfurl="true"]http://www.srh.noaa.gov/data/forecasts/NCZ101.php?warnzone=ncz101&warncounty=ncc129&quot;[/URL]

	' Opens the connection to the remote server.
	objXMLHTTP.Open &quot;GET&quot;, URL, False

	' Actually Sends the request and returns the data:
	objXMLHTTP.Send

	Dim pageContent
	pageContent = objXMLHTTP.responseText

'Now to pull out the weather
Dim temp
Response.Write &quot;<textarea cols=80 rows=40>&quot; & pageContent & &quot;</textarea>&quot;

Dim beginTempLoc, endTempLoc, temperature
Dim nextTag

'find some unique tags to search for
beginTempLoc = InStr(pageContent,&quot;<td class=&quot;&quot;big&quot;&quot; width=&quot;&quot;120&quot;&quot; align=&quot;&quot;center&quot;&quot;>&quot;)+len(&quot;<td class=&quot;&quot;big&quot;&quot; width=&quot;&quot;120&quot;&quot; align=&quot;&quot;center&quot;&quot;>&quot;)

'search after that first location for the F in degrees
endTempLoc = InStr(beginTempLoc,pageContent,&quot;&deg;F&quot;,1) + 6 'length of &deg;F

'set a string to everything between the start and end
temperature = mid(pageContent,beginTempLoc,endTempLoc - beginTempLoc)

Dim numTemp, strWeather
'weather was listed first, lets get everything up to the nextTag
strWeather = Left(temperature,InStr(temperature,&quot;<&quot;)-1)	'don't actually want the tag so subtract 1
numTemp = Right(temperature,len(temperature) - InStrRev(temperature,&quot;>&quot;))

Response.Write &quot;<br>The weather is &quot; & strWeather & &quot;<br>&quot;
Response.Write &quot;The current temperature is &quot; & numTemp & &quot;<br>&quot;
%>

Hope this proves useful,
-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top