I am trying to scrape some reddits using a software. Here is an example of subreddit that I am scraping: https://www.reddit.com/r/NFTExchange/
The software just scrapes the first page. For other pages, it is asking for Javascript code to either "load next page" or "load more data". I have tried searching codes on stackoverflow but no code is helping.
Here is what I tried but on loading next page, it scrapes first page again
var lastId;
function load(params) {
params = params || {};
$.getJSON("http://www.reddit.com/r/pics/.json?jsonp=?", params, function (data) {
var children = data.data.children;
$.each(children, function (i, item) {
$("<img/>").attr("src", item.data.url).appendTo("#images");
});
if (children && children.length > 0) {
lastId = children[children.length - 1].data.id;
} else {
lastId = undefined;
}
});
}
load();
$('.after').click(function () {
if (lastId) {
load({
after: 't3_' + lastId
});
}
})