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 2 of 2

Thread: How can I search for specific content on a web site?

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

    Default How can I search for specific content on a web site?

    I am trying to make a program to go on a stock website find the value a particular stock is at and display it to the user. Then repeat at your selected timeframe.

    I can get my code to read the entire source of the page or open a page but I cannot seem to get it to find something within the source.

    To give you a better idea of what I would it to do when completed.
    Get input from the user on what stock and sight to search and how often to check it. Once the run button is clicked I would like it to take the input from the user and run in the back ground going on the website searching the stock and display the numbers back to the user. I have only been able to have it display the entire source code though, not just the stock numbers.

    If anyone has some suggestions I would appreciate it.

    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();
    		}
     
    	}
     
    }
    Last edited by MrJava; February 28th, 2014 at 02:57 PM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,360
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: How can I search for specific content on a web site?

    Are you asking how to find a String inside another String?

    What String are you searching? What String are you searching for?

    I suggest providing an SSCCE that uses hard-coded Strings to demonstrate your approach and exactly what isn't working about it. Note that this should *not* be your full program, just a main() method that contains two hard-coded Strings and your searching logic.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Web Content Management
    By librue in forum Totally Off Topic
    Replies: 0
    Last Post: September 30th, 2012, 11:04 PM
  2. search for specific line in the file
    By Rajitha in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 16th, 2012, 09:18 AM
  3. Java program for downloading contents from the web
    By alley in forum Java Networking
    Replies: 8
    Last Post: June 17th, 2009, 01:13 PM