I am trying to make a field ‘quantity’ editable in a HTML table by replacing with HTML <input> tag using Pandas.
Code Snippet:
soup = BeautifulSoup(fp, features="lxml")
data_frame = pd.read_html(StringIO(str(soup.findAll('table'))))
position_data_frame = data_frame[4]
allTextFields = position_data_frame.get('quantity').apply(lambda x: f'''<input type="text" name="pos-{index}" value="{x}">''')
I want to assign name to the each <input> DOM using index so that i can read the values during form submission.
Expected output:
<input type="text" name="pos-1" value="10">
<input type="text" name="pos-2" value="20">
and so on....
I don’t know how to use the “index” here to use it like name=”pos-{index}”.
Question:
- Any idea how to do this?
- Is there any other library i can use which can use the same task?
This is how the HTML looks like after editing the quantity field. It doesn’t have the “name” attribute yet.
Note:- The html i am trying to edit is generated using json2html lib from a JSON output. The file doesn’t contain any ID for a field, CSS, or Javascript. It only has basic HTML tags and <table> tags.