public void fetchPages() throws IOException, SAXException, ParserConfigurationException {
    // Look at the first page with the originalURL:
    int firstAdNum = 0;
    int maxAdsPerPage = 0;
    boolean firstLoop = true;
    // maxAdsPerPage is set to the number of ads on the first page;
    // subsequent pages will never have more ads than the first page.
    List<Ad> currentPagesAds;
    do {
      URL currentURL = new URL(originalURL + firstAdNum);
      currentPagesAds = PageParser.fromInputStream(currentURL.openStream());
      for (Ad ad : currentPagesAds) {
        allAds.add(ad);
      }
      if (firstLoop) {
        maxAdsPerPage = (currentPagesAds.size());
      }
      firstLoop = false;
      firstAdNum += maxAdsPerPage;
      // Pull ads from the next page if it exists.
    } while (currentPagesAds.size() == maxAdsPerPage && maxAdsPerPage > 0);
  }