3
How to browse pages that are in a web page bar?
Specific case: When performing a query on the TCM-Ba website, on the page that records the expenses of municipalities, it is possible to access some information. It turns out that the TCM page limits the result of each page to 20 records (lines). If the user wants to have access to other data, he has to navigate through a bar with subsequent pages (see image below):
Link: Here
Link: Here
It is possible to notice the link above that to access the page, the GET protocol is used. When browsing between pages, it turns out that the only variable that changes is "pag=". The problem is that each municipality + entity (city hall or chamber) will present a varied number of pages.
I even imagined the possibility to create a loop to scrape this data... then, when the Web Scraping identified that it would be the last page... it would jump (next) to the next counter of the loop (in which case it would be the next municipality).
To identify this last page, I thought to put an error handling if the page number was invalid, eg: 27
However, what appears is this page (image below). I also thought of putting an IF to identify if the table TAG (#tableResult) appeared or not... but, even on a page that has no results, the tag appears (image below).
Link: Here
Excellent!!! Thank you very much. It worked perfectly!!!
– George Santiago