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: Problem to get info from HTML file

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem to get info from HTML file

    I am trying to get all the text from following URL "https://svenskaspel.se/p4.aspx?pageid=264".

    But the problem is that I canīt get the text from the specific tag, and I have no idea why I canīt get the text between the tag.
    Here is my code.

    public getExpert(){
     
                try {
                    sc = new Scanner(new URL("https://svenskaspel.se/p4.aspx?pageid=264").openStream(), "iso-8859-1");
                } catch (IOException ex) {
                    Logger.getLogger(getTips.class.getName()).log(Level.SEVERE, null, ex);
                }
     
                        String s = null;
                        do {
                            s = sc.nextLine();
     
                            Matcher m = Pattern.compile("<SPAN\\b[^>]*CLASS=\"mbr entry-content>(.*?)</SPAN>").matcher(s);
                            if (m.find()) {
     
                                System.out.println(m.group(1).trim());
                            }
                        } while (sc.hasNextLine() && !s.matches("<SPAN\\b[^>]*CLASS=\"mbr entry-content>(.*?)</SPAN>"));
     
     
     
         }
    }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Problem to get info from HTML file

    I did some tests using this slightly edited code:

    		try {
    			Scanner sc = new Scanner(new URL("https://svenskaspel.se/p4.aspx?pageid=264").openStream(),"iso-8859-1");
     
    			while(sc.hasNextLine()){
     
    				String s = sc.nextLine();
     
    				Matcher m = Pattern.compile("<SPAN\\b[^>]*CLASS=").matcher(s);
     
    				if (m.find()) {
    					System.out.println(m.group(0));
    					//System.out.println(s);
    				}				
     
    			}
     
    		} catch (IOException e) {
    			System.out.println("Ouch! " + e);
    		}

    It returns results but not the exact results you are looking for.
    I think you need to play with your regular expression.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. [SOLVED] Get data from HTML file
    By zecute in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 8th, 2011, 09:12 AM
  2. [SOLVED] Storing info into a text file & adding to it
    By BlackFlame in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2011, 09:06 PM
  3. [SOLVED] writing html file in a jeditorpane
    By nasi in forum AWT / Java Swing
    Replies: 3
    Last Post: May 8th, 2010, 09:39 PM
  4. how to transform an html file to a web site in java
    By nasi in forum Java Theory & Questions
    Replies: 9
    Last Post: March 28th, 2010, 11:06 PM
  5. SIGAR to find CPU info-problem
    By ttsdinesh in forum Exceptions
    Replies: 7
    Last Post: October 4th, 2009, 10:33 AM