title: How to Crawl Over a Single Website using Jsoup?
body: <p>I am starting of from a websites homepage. I am parsing the entire web page and I am collecting all the links on that homepage and putting them in a queue. Then I am removing each link from the queue and doing the same thing until I get the text that I want. However if I get a link like youtube.com/something then I am going to all the links on youtube. I want to restrict this.</p>
  
  <p>I want to crawl within the same domain only. How do I do that?</p>
  
  <pre><code>private void crawler() throws IOException {
      while (!q.isEmpty()){
          String link  = q.remove();
          System.out.println("------"+link);
          Document doc = Jsoup.connect(link).ignoreContentType(true).timeout(0).get();
          if(doc.text().contains("publicly intoxicated behavior or persistence")){
              System.out.println("************ On this page ******************");
              System.out.println(doc.text());
              return;
          }
          Elements links = doc.select("a[href]");
          for (Element link1 : links){ 
              String absUrl = link1.attr("abs:href");
              if (absUrl == null || absUrl.length() == 0) {
                  continue;
              }
  //          System.out.println(absUrl);
              q.add(absUrl);
          }
      }
  }
  </code></pre>