Hi Shatabdi,
Your code is not the proper way to do this, as Discourse dynamically adds posts when you scroll. You’d need to use at least Discourse Javascript API for this, and maybe a plugin, depending on what you want to achieve exactly.
Did you try Discourse Advertising? This plugin may do what you need, and then you won’t have to develop your own plugin.