<commit_before>var Xray = require('x-ray'),
    fs = require('fs')

var x = Xray()

var baseURLPrefix = "http://www.thaischool.in.th/sitemap.php?school_area=&province_id=",
    baseURLSuffix = "&schooltype_id=&txtsearch=",
    provinces = require('./provinces.json')

function appendObject(obj){
  var resultFile = fs.readFileSync('./result/result.json')
  var result = JSON.parse(resultFile)
  result.push(obj)
  var resultJSON = JSON.stringify(result)
  fs.writeFileSync('./result/result.json', resultJSON)
}

provinces.map(function(province){
  x(baseURLPrefix + province['id'] + baseURLSuffix, 'form', ['td > a'])
    .paginate('a[title="Next"]@href')(function(err, arr) {
      appendObject({
        province: province['name'],
        schools: arr
      })
    })
})<commit_msg>Save result as array of school name only<commit_after>var Xray = require('x-ray'),
    fs = require('fs')

var x = Xray()

var baseURLPrefix = "http://www.thaischool.in.th/sitemap.php?school_area=&province_id=",
    baseURLSuffix = "&schooltype_id=&txtsearch=",
    provinces = require('./provinces.json')

function appendObject(obj){
  var resultFile = fs.readFileSync('./result/result.json')
  var result = JSON.parse(resultFile)
  result.push(obj)
  var resultJSON = JSON.stringify(result)
  fs.writeFileSync('./result/result.json', resultJSON)
}

function appendArray(arr){
  var resultFile = fs.readFileSync('./result/schools.json')
  var result = JSON.parse(resultFile)
  Array.prototype.push.apply(result, obj);
  var resultJSON = JSON.stringify(result)
  fs.writeFileSync('./result/schools.json', resultJSON)
}

provinces.map(function(province){
  x(baseURLPrefix + province['id'] + baseURLSuffix, 'form', ['td > a'])
    .paginate('a[title="Next"]@href')(function(err, arr) {
      appendObject({
        province: province['name'],
        schools: arr
      })
      appendArray(arr)
    })
})
{'fraction_non_alphanumeric': 0.16781365802011647, 'fraction_numerical': 0.0, 'mean_word_length': 4.279329608938547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5051341', 'n_tokens_mistral': 638, 'n_tokens_neox': 637, 'n_words': 109}