How to edit page code with python mechanize?

62 views Asked by At

I have some code on page like this:

<div class="tabs1_cnt" id="pupil_tabs_content_2189609">
    <div class="pupil_tabs_content_item tabs1_cb" id="pupil_tabs_daybook_1111111" style="display: none;"></div>
    <div class="pupil_tabs_content_item tabs1_cb" id="pupil_tabs_timetable_1111111" style="display: none;"></div>
    <div class="pupil_tabs_content_item tabs1_cb" id="pupil_tabs_progress_1111111" style="display: none;"></div>
    <div class="pupil_tabs_content_item tabs1_cb" id="pupil_tabs_progress_clubs_1111111" style="display: none;"></div>
</div>

Is there any way to edit this line (2nd line) with python mechanize:

<div class="pupil_tabs_content_item tabs1_cb" id="pupil_tabs_daybook_1111111" style="display: none;"></div>

to remove "style" tag (like this):

<div class="pupil_tabs_content_item tabs1_cb" id="pupil_tabs_daybook_1111111">

Thank you in advance!

1

There are 1 answers

0
Andrii On

you can use find and after this slice your string: For example:

s = '<div class="pupil_tabs_content_item tabs1_cb" id="pupil_tabs_daybook_1111111" style="display: none;"></div>'
f = s.find('style')
final = s.find('"', f+8)
FINAL_STRING = s[:f] + s[final+1:]
print(FINAL_STRING)
# OUTPUT: <div class="pupil_tabs_content_item tabs1_cb" id="pupil_tabs_daybook_1111111" ></div>```