So say I'm using BeautifulSoup to parse pages and my code figures out that there are at least 7 pages to a query.
The pagination looks like
1 2 3 4 5 6 7 Next
If I paginate all the way to 7, sometimes there are more than 7 pages, so that if I am on page 7, the pagination looks like
1 2 3 7 8 9 10 Next
So now, I know there are at least 3 more pages. I am using an initial pass to figure out how many pages i.e. get_num_pages returns 7
What I am doing is iterating over items on each page so I have something like
for page in range(1,num_pages + 1):
# do some stuff here
Is there a way to dynamically update the range if the script figures out there are more than 7 pages? I guess another approach is to keep a count and as I get to page 7, handle that separately. I'm looking for suggestions and solutions for the best way to approach this.