Scrappy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseTable(tbl) { | |
return tbl.find('tbody tr').map(function () { | |
return $(this).find('td').map(function () { | |
return $.trim($(this).text()); | |
}).get().join('\t'); | |
}).get().join('\n'); | |
} | |
var i = 0, page = 1, pages = 1; | |
(function loop() { | |
while (!addresses[i]) { | |
i += 1; | |
results.push(''); | |
} | |
var addr = addresses[i].split('\t'); | |
$.post('search.asp?pagenum='+page, { | |
St_No: addr[0], | |
search: 1, | |
St_Name: addr[1] | |
}, function (result) { | |
result = $(result); | |
var tbl = result.find('table:eq(1)'), | |
last_link = tbl.nextAll('div:first').find('a:last')[0]; | |
if (last_link) | |
pages = +last_link.href.split('=')[1] || 1; | |
results.push(parseTable(tbl)); | |
console.log(i, addresses[i], tbl, last_link, pages); | |
if (page <= pages) | |
page += 1; | |
if (page > pages) { | |
i += 1; | |
page = 1; | |
pages = 1; | |
} | |
i < addresses.length && loop(); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment