0

Good Afternoon,

With Yahoo Finance, following the following link, along with some convenient URL tags, will customize a downloadable CSV with nearly whatever stock information you like. The URL will automatically download a CSV to wherever your downloads default:

http://finance.yahoo.com/d/quotes.csv?s="GOOG"+&f="s"

I, however, do not want to download this content on to my computer, I would like to download it into a webpage. Here is what I've been toying with:

The JSP, index.jsp:

<!DOCTYPE JSP>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<script src="Scripts/script.js"></script>
<style>
#Generic_Container {
height:500px;
width:500px;
background-color:transparent;
}
#Link1 {
width:200px;
height:200px;
position:absolute;
top:5px;
left:5px;
background-color:blue;
color:white;
}
</style>
</head>
<body>
<div id="Generic_Container">
    <a href='http://finance.yahoo.com/d/quotes.csv?s="GOOG"+&f="s"' id='Link1'></a>
</div>
</body>
</html>

and the related file, script.js (poor naming conventions, I realize; however, this example is for inquisitive purposes alone):

$('document').ready(function() {

$('#Link1').click(function(event) {
    event.preventDefault();
    $('#Link1').load('http://finance.yahoo.com/d/quotes.csv?s="GOOG"+&f="s"');
});

});

this should prevent the download of the file from the site, and instead load the content into the frame, but I must be doing something wrong. I'm also open to alternative methods of getting this done, if I'm indeed doing something not-so-logical..

4

1 回答 1

0

Suggest using Yahoo's YQL AJAX proxy service to return the data as jsonp and parse it to html from there. The YQL sandbox console has examples how to retrieve quotes

YQL Console Quote Example

Once you get the url set up in console, can use $.getJSON to retrieve the data.

Other option is to use a proxy on your own server that retrieves the csv using CURL and parses to html or json for you to retrive with AJAX

于 2013-03-30T23:27:55.707 回答