Python Forum
reading html and edit chekcbox to html
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading html and edit chekcbox to html
#1
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:
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
Reply


Messages In This Thread
reading html and edit chekcbox to html - by jacklee26 - Jun-30-2021, 01:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  WebElements of an HTML page Nik1811 2 362 Mar-14-2024, 12:39 PM
Last Post: Nik1811
  Going through HTML table with selenium emont 3 816 Sep-30-2023, 02:13 AM
Last Post: emont
  Need to replace a string with a file (HTML file) tester_V 1 775 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  why doesn't it replace all html tags? Melcu54 3 757 Jul-05-2023, 04:47 AM
Last Post: Melcu54
  pyscript index error while calling input from html form pyscript_dude 2 991 May-21-2023, 08:17 AM
Last Post: snippsat
  html module in python 3.6.8 suifra 9 1,636 May-12-2023, 11:30 AM
Last Post: suifra
  How to display <IPython.core.display.HTML object>? pythopen 3 45,998 May-06-2023, 08:14 AM
Last Post: pramod08728
  Embedding python script into html via pyscript pyscript_dude 7 1,568 Apr-16-2023, 11:17 PM
Last Post: pyscript_dude
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 934 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
  BeautifulSoup - I can't translate html tags that contain <a href=..</a> OR <em></em> Melcu54 10 1,643 Oct-27-2022, 08:58 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020