Issue with searching table html and <tbody> tags

Just so everyone knows where I’m coming from, I’m not a developer, I used GitHub copilot and some other chatbots to write this code.

My addon is for editing tables and I’m trying to add an Apply to All button so that when a user updates a table on one card it searches all the cards for that table and updates them as well

However, for some reason, tags randomly appear/don’t appear in the html causing the search to not find all the tables

Anyone have any ideas??

Here’s a link to the function

Here’s a link to the PR with the bug

Some print statements I got from the console: “initial-html” is what it’s searching for. I have gotten the function to be able to find all instances of the table (print statement tells me how many were found) but when it goes to update them the <tbody> tags get in the way (I have print statements show the html of the “unmatched” tables and there are <tbody> tags) that are not in the initial_html

Console output:

initial_html has been updated to: <table border="1" class="one"><tbody><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></tbody></table>
Starting to apply changes to all notes...
Searching for notes containing the table: <table border="1" class="one"><tbody><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></tbody></table>
blocked main thread for 244ms:
  File "C:\Users\shmue\OneDrive - student.touro.edu\Documents\GitHub\AnkingTables\runanki.py", line 28, in <module>
    run_anki()
  File "C:\Users\shmue\OneDrive - student.touro.edu\Documents\GitHub\AnkingTables\runanki.py", line 23, in run_anki
    aqt.run()
  File "C:\Users\shmue\AppData\Local\Programs\Python\Python39\lib\site-packages\aqt\__init__.py", line 519, in run
    _run()
  File "C:\Users\shmue\AppData\Local\Programs\Python\Python39\lib\site-packages\aqt\__init__.py", line 733, in _run
    app.exec()
  File "C:\Users\shmue\AppData\Roaming\Anki2\addons21\anking_tables\main_window.py", line 182, in <lambda>
    lambda: self.apply_changes_to_all(mw.col, self.htmlEditor.toPlainText()))
  File "C:\Users\shmue\AppData\Roaming\Anki2\addons21\anking_tables\main_window.py", line 431, in apply_changes_to_all
    note_ids.extend(col.find_notes(original_table))
  File "C:\Users\shmue\AppData\Local\Programs\Python\Python39\lib\site-packages\anki\collection.py", line 675, in find_notes
    Sequence[NoteId], self._backend.search_notes(search=query, order=mode)
  File "C:\Users\shmue\AppData\Local\Programs\Python\Python39\lib\site-packages\anki\_backend_generated.py", line 1637, in search_notes
    raw_bytes = self._run_command(27, 2, message.SerializeToString())
  File "C:\Users\shmue\AppData\Local\Programs\Python\Python39\lib\site-packages\anki\_backend.py", line 169, in _run_command
    print("".join(traceback.format_stack()))

Found 10 notes that contain the original tables.
Note IDs: [1463081222466, 1463081859526, 1463081757542, 1463081896488, 1522882331271, 1463081820748, 1463081930386, 1522882308732, 1522882255646, 1463081611935]
No matching table found in note 1463081222466, field 1
Table of unmatched note: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
No matching table found in note 1463081859526, field 1
Table of unmatched note: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
Found a matching table in note 1463081757542, field 1
Table of matching note: <table border="1" class="one"><tbody><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></tbody></table>
Replacing the table with: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
Updated field content: <div><table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table></div>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <img src="tmpsMGdo_.png"/>
Updated field content: 
Updated field content: <img src="22a8eac217530c2fdc8f0e28467054ba.jpg"/><br/><img alt="Lesson Review" src="dd4701353f98a5cf32a4f0c4b79997e6.webp"/>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <div class="ome-widget"><a href="https://learn.onlinemeded.com/collections/pediatrics?ref=anki"><img src="_OME_AnkiFlashcards_Topic_1.png"/></a></div><br/>
Updated field content: 
Updated field content: y
Updated field content: f7b16545-e027-43b9-86a8-194b2fd48c1e
Updated note with ID: 1463081757542
Found a matching table in note 1463081896488, field 1
Table of matching note: <table border="1" class="one"><tbody><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></tbody></table>
Replacing the table with: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
Updated field content: <div><table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table></div>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <img src="tmpsMGdo_.png"/><br/>
Updated field content: 
Updated field content: <img src="22a8eac217530c2fdc8f0e28467054ba.jpg"/><br/><img alt="Lesson Review" src="dd4701353f98a5cf32a4f0c4b79997e6.webp"/>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <div class="ome-widget"><a href="https://learn.onlinemeded.com/collections/pediatrics?ref=anki"><img src="_OME_AnkiFlashcards_Topic_3.png"/></a></div><br/>
Updated field content: 
Updated field content: y
Updated field content: 859fea69-0b3e-482b-89aa-b2fef2c01707
Updated note with ID: 1463081896488
No matching table found in note 1522882331271, field 1
Table of unmatched note: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
Found a matching table in note 1463081820748, field 1
Table of matching note: <table border="1" class="one"><tbody><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></tbody></table>
Replacing the table with: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
Updated field content: <div><table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table></div>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <img src="tmpsMGdo_.png"/><br/>
Updated field content: 
Updated field content: <img src="22a8eac217530c2fdc8f0e28467054ba.jpg"/><br/><img alt="Lesson Review" src="dd4701353f98a5cf32a4f0c4b79997e6.webp"/>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <div class="ome-widget"><a href="https://learn.onlinemeded.com/collections/pediatrics?ref=anki"><img src="_OME_AnkiFlashcards_Topic_2.png"/></a></div><br/>
Updated field content: 
Updated field content: y
Updated field content: 64d346e8-70bd-4cff-906a-44863a3d54d7
Updated note with ID: 1463081820748
No matching table found in note 1463081930386, field 1
Table of unmatched note: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
No matching table found in note 1522882308732, field 1
Table of unmatched note: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
Found a matching table in note 1522882255646, field 1
Table of matching note: <table border="1" class="one"><tbody><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></tbody></table>
Replacing the table with: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
Updated field content: <div>APGAR scores not related to long-term outcomes → just an objective measure to see if the neonate is <b>improving</b> in the first few minutes</div><br/><br/><div><table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table></div>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <img src="fefeec77078750f15351061934ac0313.jpg"/><br/><img alt="Lesson Review" src="dd4701353f98a5cf32a4f0c4b79997e6.webp"/>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <div class="ome-widget"><a href="https://learn.onlinemeded.com/courses/take/pace-cs-pediatrics-2-neonatal/pdfs/39348109-prime-notes?ref=anki"><img src="_OME_AnkiFlashcards_Lesson_5.png"/></a></div><br/>
Updated field content: OME:<br/><div><img src="paste-88596585381889_1522849603677.jpg"/></div>
Updated field content: 
Updated field content: 04dc3e4e-480e-48a3-8a45-346ac2652d7d
Updated note with ID: 1522882255646
Found a matching table in note 1463081611935, field 1
Table of matching note: <table border="1" class="one"><tbody><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><td>Appearance</td><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><td>Pulse</td><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><td>Grimace</td><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><td>Activity</td><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><td>Respiration</td><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></tbody></table>
Replacing the table with: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
Updated field content: <table border="1" class="one"><tr><th></th><th>0 Points</th><th>1 Point</th><th>2 Points</th></tr><tr><th>Appearance</th><td>Pale or blue</td><td>Extremities blue</td><td>Pink</td></tr><tr><th>Pulse</th><td>No pulse</td><td>&lt; 100 bpm</td><td>≥ 100 bpm</td></tr><tr><th>Grimace</th><td>No response to stimulation</td><td>Grimaces or weak cry</td><td>Cries and pulls away</td></tr><tr><th>Activity</th><td>No movement</td><td>Arms, legs flexed </td><td>Active movement </td></tr><tr><th>Respiration</th><td>No breathing</td><td> Slow, irregular</td><td>Strong cry </td></tr></table>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <img src="tmpsMGdo_.png"/><br/>
Updated field content: 
Updated field content: <img src="22a8eac217530c2fdc8f0e28467054ba.jpg"/><br/><img alt="Lesson Review" src="dd4701353f98a5cf32a4f0c4b79997e6.webp"/>
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: 
Updated field content: <div class="ome-widget"><a href="https://learn.onlinemeded.com/collections/pediatrics?ref=anki"><img src="_OME_AnkiFlashcards_Topic_6.png"/></a></div><br/>
Updated field content: 
Updated field content: y
Updated field content: dc33990d-2244-4fb5-a745-38df185e0d51
Updated note with ID: 1463081611935
Updated a total of 5 notes.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.