<commit_before>import cheerio from 'cheerio';
import URI from 'urijs';

import request from './request';

class LinkSpider {
  
  async main(url, depth) {
    
    const inputHost = new URI(url).hostname()
    console.log(inputHost)
    
    let history = {}
    
    
    let newUrls = []
    
    const resp = await request.get(url)
    
    const $ = cheerio.load(resp.body);
    
    let elements = $('a')
    for (let i = 0; i < elements.length; i++) {
      const element = elements[i];
      let url = $(element).attr('href')
      let newHost = new URI(url).hostname()
      
      // If this link is to a different site, ignore. 
      if (newHost !== inputHost) {
        continue;
      }
      
      // Already saw this url, continue
      if (history[url]) {
        continue;
      }
      
      history[url] = true;
      
      
      newUrls.push(url)
      
      
      // new URI(googleMapSrc).
    }
    
    
    // console.log(a)
    
    
    
    
    
    
  }
  
  
}



const instance = new LinkSpider()

instance.main('https://camd.northeastern.edu/artdesign/community/faculty-staff/')<commit_msg>"jawnnnn"<commit_after>import cheerio from 'cheerio';
import URI from 'urijs';

import request from './request';

class LinkSpider {
  
  async main(inputUrl, depth = 1) {
    
    const inputHost = new URI(inputUrl).hostname()
    
    let history = {}
    let urlStack = [inputUrl]
    let newUrls = []
    
    while (depth > 0) {
      
      let promises = []
      
      // Get all the links from all of the URLs
      for (let url of urlStack) {
        promises.push(request.get(url))
      }
      
      let responses = await Promise.all(promises)
      
      let linksOnPages = []
      
      responses.forEach(function(resp) {
        
        const $ = cheerio.load(resp.body);
        let elements = $('a')
        for (let i = 0; i < elements.length; i++) {
          const element = elements[i];
          let url = $(element).attr('href')
          if  (!url) {
            continue;
          }
          let newHost = new URI(url).hostname()
            
            
          // If this link is to a different site, ignore. 
          if (newHost !== inputHost) {
            continue;
          }
          
          // Already saw this url, continue
          if (history[url]) {
            continue;
          }
          
          history[url] = true;
        
          linksOnPages.push(url)
        }
      })
      
      urlStack = linksOnPages;
      depth --;
      
      
    }
    
    return urlStack
  }
}



const instance = new LinkSpider()


async function main() {
  
  let a  = await instance.main('https://camd.northeastern.edu/artdesign/community/faculty-staff/')
  
  console.log(JSON.stringify(a, null, 4))  
}

main()


{'fraction_non_alphanumeric': 0.1175, 'fraction_numerical': 0.0017857142857142857, 'mean_word_length': 1.5579908675799086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '733717', 'n_tokens_mistral': 882, 'n_tokens_neox': 865, 'n_words': 208}