So I have this table, and I want to go through in Python, and find all of the <tr> tags, and turn them into <tr id="NUMBER HERE"> where the number will be a number from a list which is in this format:
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '47']
What is the best way to do this?
So basically, the first <tr> would become <tr id="1"> the second would become <tr id="2">, etc.
It is NOT always sequential, as you can see from it going from 20 to 47.
The table is stored as a string.
I should specify, currently, it is a string with multiple tags, i.e. <html><table><tr>blah</tr><tr>blahblah</tr></table></html> – VERY oversimplified. I want it to search for the instances of <tr> in the string and replace each with <tr id="NUMBER">, based on the position of the tr versus the next number in the list.
Using lxml:
yields