Can somebody please help me?

I need help in creating a script which is related to page navigation. The page what I am trying to record has a maximum of 5 html links on it. A 'next' html link appears, if there are more than 5 links. It looks as below.
previous < 1 2 3 4 5 > Next
If you click 'next' link, it will take you to the next set of links(ex: 6 7 8 9 10). If you click each link, it will result a html table of ten entries.
I need to count entries in html table of all pages. I am stuck with navigation. Can somebody please help me how to create a script for this type?

I can count on one page using table functions. But how to handle this type of page navigation?

Please help. Vey very ******.