Jun-30-2021, 01:50 PM
I have a question about reading HTML files, and edit by adding a checkbox before a tag on every link.
I have a test.html that looks like this:
i wish my output will be like this, add a checkbox before each link which should look like this
Does anyone know how to do solve it?
Step:
Read test.html
edit the test.html adding <checkkbox> before a tag
I have a test.html that looks like this:
Quote:<a href="https://www.google.com">Link </a><br><a href="https://www.youtube.com">Link </a><br><a href="https://www.instagram.com">Link </a><br>
i wish my output will be like this, add a checkbox before each link which should look like this
<input type="checkbox"> <a href="https://www.google.com">Link </a><br> <input type="checkbox"> <a href="https://www.youtube.com">Link </a> <input type="checkbox"> <a href="https://www.instagram.com">Link </a>Do anyone have any idea i try like this but seem not working
lines = [] #open file with open(r'test.html', mode='r') as f: for line in f.readlines(): # iterate thru the lines if '<br>' in line: text = '<input type="checkbox">' lines.append(text) lines.append(line) #write to a new file with open(test.html', mode='w') as new_f: new_f.writelines(lines)I think I need to add a new line after <br> else it won't work.
Does anyone know how to do solve it?
Step:
Read test.html
edit the test.html adding <checkkbox> before a tag