Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Lab 8: Getting on-line stock quotes from Yahoo (with a Socket ) This lab is an example of interacting with an HTTP server to retrieve a web page from a system on the network. Here HTML forms are used.

Lab 8: Getting on-line stock quotes from Yahoo (with a Socket )

This lab is an example of interacting with an HTTP server to retrieve a web page from a system on the network. Here HTML forms are used. HTML forms allow you to type some information in your browser which is sent back to the server for processing. The information may be encoded as part of the URL, or sent separately in name/value pairs.

The Yahoo site is a wide-ranging access portal. They offer online stock quotes that you can read in your browser. A request for a stock quote for ABCD is translated to a socket connection of:

http://finance.yahoo.com/q?s=abcd

That’s equivalent to opening a socket on port 80 of finance.yahoo.com and sending a “get /q?s=abcd”. You can make that same request yourself, in either of two ways. You can open a socket connection to port 80, the http port. Or you can open a URL connection which offers a simpler, higher-level interface, which you did it in lab 7.

The Yahoo page that returns stock quotes contains thousands of characters of href ads and formatting information. It consists of many HTML lines like this:

SUNW

align=center>12:03PM9.55

It is fairly easy to pull out the stock price. From inspecting the output, it’s on a line with more than 25 chars. The line contains the stock symbol rewritten in upper case. The number you want is bracketed by …, which is the HTML to print the number in bold face.

Note: Yahoo site changes each year or once in a while the format of its finance webpage changes. So, you need to figure out what has changed for this assignment and plan your solution accordingly. For 2018, the web site has removed its link for http access as I understand. All sites nowadays use HTTPS (HTTP Secure). I suggest using CNN money site as shown below for trying to find IBM stock price:

https://money.cnn.com/quote/quote.html?symb=IBM

So, you need to build your Get command with its query string so that it points to the above URL. And your parsing approach would be different as you will find its stock price in a line like shown below (first occurrence of MorningstarQuote may be one way to catch the string for this price):

124.79

Your Lab 8 assignment is to write a program that uses the  SSLSocket class to create a connection to host money.cnn.com and port 443. You provide the symbol for a specific stock in your command line. Your program could apply getOutputStream() method to the secure socket in order to open an outputStream for writing to the CNN site.

Send the name/value pair (i.e., symb=ibm) in a GET request to the remote host as the CNN site expects. Then read the returned information which is in the format described above. Parse and extract the characters of interest that is the price between ="MorningstarQuote">124.79

Please study relevant pages of your textbook on chapters 6, 8, and especially chapter 10 and its example 10-1 on HTTPSClient, for methods that you can use for a SSLSocket object or use any other online resource. You probably need to use and familiarize yourself with the following methods:

getOutputStream, and  getInputStream

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question