Solved

parsing question

Posted on 2004-09-02
4
163 Views
Last Modified: 2010-03-31
hi im trying to get a simple parser going below is my bit of code, I m to read all the contents of an url and store it in a database, the question is how do i know when i reached the end of a page? so that i know when to store everything in my database and move on to the next link

 public void handleStartTag(HTML.Tag t,MutableAttributeSet a, int p)
{  
               if (t == HTML.Tag.A)
      {
                 ahreflink = (String)a.getAttribute(HTML.Attribute.HREF);
                 searchList.add(ahreflink);

                }
      
          if (t == HTML.Tag.TITLE)
                 {    
                  titleFlag=true;
                  }


}

            public void handleText(char[] data, int pos)
            {         
            try{
                title = new String(data);
                content =new String(data);
                  
                  if(titleFlag==false)
                    {                        
                       text = text + " " + content;                   
                  }      
            
                        if(titleFlag==true)
                        {
                         System.out.println("Title: "+ title);
                         titleFlag=false;
                        }

                  }catch(Exception p){p.printStackTrace();}                          
            }//end of handleText


0
Comment
Question by:HomerrSimpson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Assisted Solution

by:primusmagestri
primusmagestri earned 20 total points
ID: 11962861
Look for the html end tag: </html>. After this tag you can, at most, have some comments.
0
 
LVL 35

Accepted Solution

by:
TimYates earned 80 total points
ID: 11962896
public void handleEndTag( HTML.Tag t, int pos )
0
 

Author Comment

by:HomerrSimpson
ID: 11963108
do you mean something like

public void handleEndTag(HTML.Tag t, int pos)
{
   if (t == HTML.Tag.HTML)
     {

    store "text" in database
    }



}
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11963367
yup...that should do it...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 52
Android development question 2 81
Java: The Public Class Main 4 45
DTD and JAVA versions 1 33
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question