title: How to navigate websites using Jsoup in java
body: <p>How can i navigate (like web crawling) in Jsoup to a different link?</p>
  
  <p>For this example I have done the basics to get the title, get links and get texts. But I want to be able to use one of those child links and go to the inside of that child link. </p>
  
  <p>For example from google web page I want to be able to go to youtube page because its one of the child links in google and once in youtube pick another child link and than be able to grab a string.</p>
  
  <p>How would I be able to do this in Jsoup?</p>
  
  <pre><code>import java.io.IOException;
  
  import org.jsoup.Jsoup;
  import org.jsoup.nodes.Document;
  import org.jsoup.nodes.Element;
  import org.jsoup.select.Elements;
  
  
  public class JSoupTest {
  
  
  public static void main(String args[]) {
  
      try {
  
  
          Document doc=Jsoup.connect("http://www.google.com").get();
  
          // get page title
          String title = doc.title();
          System.out.println(title);
  
          //gets all links
          Elements links = doc.select("a[href]");
          for (Element link : links) {
  
          // get the value from href attribute
          System.out.println("\nlink : " + link.attr("href"));
  
          }
  
          for( Element element : doc.select("p") )    
                      // Select all 'p'-Tags and loop over them
          {
              if( element.hasText() )                 
                      // Check if the element has text (since there are some empty too)
              {
                System.out.println(element.text()); // print the element's text
              }
          }
  
  
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>