How can I iterate over anchors assigned to JavaScript functions in Selenium using python?

I am working on a web scraping project using Selenium in Python. I have successfully scraped a set of anchors from a website, and I want to iterate over these anchors, click each link, run some code to extract data from the webpage, and then move to the next anchor in the set.

The anchors I’m working with look like this:

    <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Page$2')">2</a>
    <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Page$3')">3</a>

I have stored these anchors in a variable as follows:

    anchors = d.find_elements(By.XPATH, '//*[@id="ContentPlaceHolder1_GridView1"]/tbody/tr/td/table/tbody/tr/td/a')

When I attempt to iterate over the anchors and click each link, I encounter a StaleElementReferenceException. Here’s a simplified version of my code:

    i = 0
    for a in anchors:
        anchors[i].click()
        *Code to extract data from the webpage*
        i += 1

I have tried various versions of this code, including more robust solutions found in other Stack Overflow threads, but the issue persists. The error message I receive is:

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: stale element not found

I have checked that the table containing the anchors and the anchors themselves do not change when navigating between pages. The XPaths for both remain the same.

I have referred to the following Stack Overflow threads without success:

Fetch all href link using selenium in python
Selenium: Iterating through groups of elements

I would greatly appreciate any guidance or solutions to resolve this issue. Thank you in advance.