Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How do I read something specific of a web page?

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do I read something specific of a web page?

    Hello.

    I am trying to have a program go on one of the stock trading websites and read the number a stock or currency is at and display or save it.
    I have it reading and displaying the binary code but I don’t see how to have it find the numbers I would like to get.
    On the site you would have to go on the page and click some tabs to trade and maybe the stock you would like, it doesn’t really matter what one it returns as this is more just an idea I thought of that would help me learn more about programming. Although I would like to have it search out a selected stock eventually to take it to the net level. I think my biggest problem is I can’t see how to access the stock numbers in the code. I looked for different click events but don’t see how to have a program do this.

    I do not intend to have it display all the code like it is now. I just did it like that to see what I was getting. I will just have a small toolbar with options and a display.

    Sorry if this is a bit of a mess, I am new to all this but it interests me I look forward to when I can have an Idea for a app or game and bring it to like.

    If anyone can point me in the right direction that would be great.

    Thanks.

    import java.io.BufferedInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.MalformedURLException;
    import java.net.URL;
     
    public class StockTracker {
     
    	public static void main(String[] args) {
     
    		try {
    			URL url = new URL("http://www.goptions.com/trading/");
    			InputStream stream = url.openStream();
    			BufferedInputStream buf = new BufferedInputStream(stream);
     
    			StringBuilder sb = new StringBuilder();
     
    			while (true) {
    				int data = buf.read();
     
    				if (data == -1) {
    					break;
    				}
    				else {
    					sb.append((char)data);
    				}
    			}
     
    			System.out.println(sb);
    		} catch (MalformedURLException e) {
    			e.printStackTrace();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
     
    	}
     
    }


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: How do I read something specific of a web page?

    Quote Originally Posted by MrJava View Post
    			URL url = new URL("http://www.goptions.com/trading/");
    The main point is: this url, tried in a common browser (and viewing its source code), gives a very complex HTML page containing lots of things. So what can you expect from a page like that? I guess this is not what you want/expect? Why are you using this page? Is an your choice? Or someone told you to use this?
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How do I read something specific of a web page?

    how to access the stock numbers in the code
    How complicated is the html page the code reads? If there isn't anything dynamic like javascript functions updating the screen in the browser in realtime, then the problem is parsing the String that is read from the server when it returns the html page.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I read something specific of a web page?

    Yes I was told to try it. I also looked at some other trading sits but they all look complex. I might just have to start with another idea I guess.

  5. #5
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: How do I read something specific of a web page?

    Quote Originally Posted by MrJava View Post
    Yes I was told to try it. I also looked at some other trading sits but they all look complex. I might just have to start with another idea I guess.
    I checked that site using Firefox and with the Firebug extension I traced all the AJAX requests. One seems interesting:
    http://spotplatform.goptions.com/Pla...Data.spotgraph

    It returns datas in JSON format. Even if I don't understand those values, I guess they are in some way what I see on the graph in the page.
    Verify if this is what you want. If yes, you can use requests like this to get the data (and not an unuseful HTML page). At Java level this requires some work: you need a Java library to handle JSON data and you need some work to "bind" that data to Java classes. But it's perfectly possible.

    I hope I have helped.
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  6. The Following User Says Thank You to andbin For This Useful Post:

    GregBrannon (March 2nd, 2014)

  7. #6
    Junior Member
    Join Date
    Jan 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I read something specific of a web page?

    Thanks very much, that will give me something to look into.

Similar Threads

  1. How can I search for specific content on a web site?
    By MrJava in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 29th, 2014, 11:31 AM
  2. Read a specific page from .doc file
    By srautpyaa in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 1st, 2013, 09:33 AM
  3. Read Specific value
    By sarwardnj in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: March 17th, 2013, 02:05 PM
  4. Get data from web page
    By inmar32 in forum Web Frameworks
    Replies: 4
    Last Post: July 21st, 2010, 09:09 AM
  5. How to read URLs from a web page
    By abitha in forum Java Theory & Questions
    Replies: 1
    Last Post: September 17th, 2009, 12:36 PM