How to get selected hyperlink text and save in variable use only st.write href

Dear Sir,

I am writing to request your assistance with a technical matter. My code executes successfully, and when I click any hyperlink, it downloads a text file containing the text of the selected hyperlink without refreshing the page. However, I am encountering a challenge when attempting to store the selected hyperlink text in a variable. The code consistently returns the last hyperlink text from the list, regardless of which hyperlink I select. For instance, whether I select the first, second, third, or fourth hyperlink, the system always retrieves the final item from the list.

I would greatly appreciate your guidance on how to obtain the selected hyperlink text. Additionally, I must emphasize that I am not utilizing a button in my implementation, so I kindly request that you refrain from providing st.button code. Instead, I would prefer a solution using st.write href code to retrieve the selected hyperlink text.


import base64
import streamlit as st
from datetime import datetime
mmfa1 = []
st.title("Muhammad is the Best in all over the universes!")
# Get the current date and time
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
st.write(f"The current date and time is: **{current_time}**")

if "textpara" not in st.session_state:
    st.session_state.textpara = ''


def create_download_link(data_str, filename="data.txt"):
  st.title(data_str)
  mmfa1.append(data_str)
  st.session_state.textpara = data_str
  b64 = base64.b64encode(data_str.encode()).decode()
  href = f'<a href="data:file/txt;base64,{b64}" download="{filename}">Click here to download {data_str} (no refresh)</a>'
  st.session_state.textpara = data_str

  st.markdown(href, unsafe_allow_html=True)

mfa = "Teshing "
mfa1 = "1Teshing"
mfa2 = "2Teshing"
mfa3 = "3Teshing"
mfa4 = "4Teshing"
mfa5 = "5Teshing"

create_download_link(mfa, "test.txt")
create_download_link(mfa1, "test.txt")
create_download_link(mfa2, "test.txt")
create_download_link(mfa3, "test.txt")
create_download_link(mfa4, "test.txt")
create_download_link(mfa5, "test.txt")

# Show data in expander
with st.expander("See explanation"):
    st.write("Here are the detailed notes or extra info.")
    st.write(st.session_state.textpara)
for item in mmfa1:
    st.write(item)