Jul-16-2022, 09:30 AM
Hi
In a python script which creates html documents using beautifulsoup, I want to insert new lines and html comments between some tags, at specific spots inside the beautiful string, not inside the resulting html document.
As an example, starting from such a string :
<!DOCTYPE html>
<html><head><title>My html document</title></head><body><section id="register"/><section id="words"/></body></html>
I want to get this one :
With code as this
Arbiel
In a python script which creates html documents using beautifulsoup, I want to insert new lines and html comments between some tags, at specific spots inside the beautiful string, not inside the resulting html document.
As an example, starting from such a string :
<!DOCTYPE html>
<html><head><title>My html document</title></head><body><section id="register"/><section id="words"/></body></html>
I want to get this one :
Output:<!DOCTYPE html>
<html><head><title>My html document</title></head><body>
<!-----------------here is the register section -------------->
<section id="register"/>
<!-----------------here is the words section -------------->
<section id="words"/>
<!----------------- no additionnal sections -------------->
</body></html>
I have not been able to find out how to do.With code as this
from bs4 import BeautifulSoup as btfs from bs4 import Comment as cmt nl=cmt(""" """) marque='----------' #spot=locating where to insert the comment entête=btfs('', 'html.parser') entête.append(cmt(nl)) entête.append(cmt(' '.join((marque,polytonique,atonique,marque)))) entête.append(cmt(nl)) spot.insert_before(entête)I have been able to get :
Output:<section id="mots"><!--
--><!------------ ἀγαθός [αγαθος] ------------><!--
--><article id="ἀγαθός">
when I'm looking for:Output:<section id="mots">
<!------------ ἀγαθός [αγαθος] ------------>
<article id="ἀγαθός">
and also, in other situations, toOutput:<section id="mots">
<article id="ἀγαθός">
Your input will be appreciated.Arbiel