Skip to content

Instantly share code, notes, and snippets.

@jakubbalada
Created January 31, 2018 14:33
Show Gist options
  • Save jakubbalada/2873fa22518978eec3047fe6e8fe1281 to your computer and use it in GitHub Desktop.
Save jakubbalada/2873fa22518978eec3047fe6e8fe1281 to your computer and use it in GitHub Desktop.
function pageFunction(context) {
// called on every page the crawler visits, use it to extract data from it
var $ = context.jQuery;
if (context.request.label === 'start') {
context.skipOutput();
var count = parseInt($('.count').text());
for(var i=0; i<=count; i+=20) {
context.enqueuePage("http://www.topshop.com/webapp/wcs/stores/servlet/CatalogNavigationAjaxSearchResultCmd?storeId=12556&catalogId=33057&langId=-1&dimSelected=%2Fen%2Ftsuk%2Fcategory%2Fclothing-427%2FN-82zZdgl%3FNo%3D" + i + "%26Nrpp%3D20%26siteId%3D%252F12556%26categoryId%3D203984");
}
} else {
var jsonObject = JSON.parse($('body pre').text());
return jsonObject.results.contents[0].records;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment