Results 1 to 13 of 13

Thread: URL help

  1. #1
    mbschultz97 is offline Super OP Noob
    Join Date
    May 2014
    Location
    Virginia
    Posts
    65
    Rep Power
    0

    Default URL help

    Hey I'm trying to make a simple program that prints out the current price of a share in Microsoft :P So far all I've done is make it print out everything from the page:

    Java Code:
    import java.io.*;
    import java.net.*;
    
    public class GetInfo{
    
       public static void main(String[] args) throws IOException{
       
          URL example = new URL("http://www.nasdaq.com/symbol/msft");
          URLConnection connect = example.openConnection();
          InputStream stream = connect.getInputStream();
          BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
          String line = null;
          while ((line = reader.readLine()) != null){
             System.out.println(line);
          }
       }
    }
    What method do I use to get the price? Do I get the name of the variable or method that holds the price by using inspect element on google chrome? And do you have any tips on finding the variable names in the future? One more thing is this now considered advanced java or should I stick to the new java thread? thanks! :D

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: URL help

    There are many different possible pages that can be returned from a server. What does the content of the html that is returned from the website you are going to look like? Where in those lines is the data you want?
    There are some packages that will help you parse the html page.

    See this thread: How to get info from sites...
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    mbschultz97 is offline Super OP Noob
    Join Date
    May 2014
    Location
    Virginia
    Posts
    65
    Rep Power
    0

    Default Re: URL help

    Quote Originally Posted by Norm View Post
    There are many different possible pages that can be returned from a server. What does the content of the html that is returned from the website you are going to look like? Where in those lines is the data you want?
    There are some packages that will help you parse the html page.

    See this thread: How to get info from sites...
    What are the packages that will help me parse the html page and what method do i use to parse the info?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: URL help

    Look at the other site at the link.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    mbschultz97 is offline Super OP Noob
    Join Date
    May 2014
    Location
    Virginia
    Posts
    65
    Rep Power
    0

    Default Re: URL help

    I found two different places where the current price (39.54) is in the code

    <td align="right" valign="top" nowrap="nowrap"><label id="MSFT_LastSale2">$&nbsp;39.54</label></td>

    <td class="noopbg" align="right" nowrap="nowrap">$&nbsp;39.54</td>

    now how do I use it in my code and will the number change when it does on the website?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: URL help

    how do I use it in my code
    Not sure what the problem is. If you can find the desired data in the html page, you can use it in your code any way you want.
    will the number change when it does on the website?
    The html page you are reading should be exactly the same as is shown in a browser when that page is read.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    mbschultz97 is offline Super OP Noob
    Join Date
    May 2014
    Location
    Virginia
    Posts
    65
    Rep Power
    0

    Default Re: URL help

    Quote Originally Posted by Norm View Post
    Not sure what the problem is. If you can find the desired data in the html page, you can use it in your code any way you want.

    The html page you are reading should be exactly the same as is shown in a browser when that page is read.
    how do i use it in my code as in what method do i use and what would to code look like?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: URL help

    how do i use it in my code
    Use what in the code?
    What do you want to do with the data from the website? That is up to you.
    Do you want to write it to a file?
    Do you want to display in in a GUI or a dialog window?

    Why are you writing this program if you don't know what to do with the data?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    mbschultz97 is offline Super OP Noob
    Join Date
    May 2014
    Location
    Virginia
    Posts
    65
    Rep Power
    0

    Default Re: URL help

    Quote Originally Posted by Norm View Post
    Use what in the code?
    What do you want to do with the data from the website? That is up to you.
    Do you want to write it to a file?
    Do you want to display in in a GUI or a dialog window?

    Why are you writing this program if you don't know what to do with the data?
    1. use the price of the stock
    2. for now i just want to set a double equal to the price of the stock
    3. no
    4. eventually i will but i can just use the double then right?

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: URL help

    If you are having a problem with some code, post the code and explain your problem.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    mbschultz97 is offline Super OP Noob
    Join Date
    May 2014
    Location
    Virginia
    Posts
    65
    Rep Power
    0

    Default Re: URL help

    Quote Originally Posted by Norm View Post
    If you are having a problem with some code, post the code and explain your problem.
    will you tell me what method i need to use to set the price of the stock as a double??

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: URL help

    To convert a String like: "23.34" to a double use the parse method of the Double class.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    mbschultz97 is offline Super OP Noob
    Join Date
    May 2014
    Location
    Virginia
    Posts
    65
    Rep Power
    0

    Default Re: URL help

    Quote Originally Posted by Norm View Post
    To convert a String like: "23.34" to a double use the parse method of the Double class.
    I'm talking about getting the price from the website code and using it in mine... what part of the site code do i use and how do i start using it in my code?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •