title: I want to insert text in html using python
body: <p>I am a python developer and still learning, I want some help in scraping concept, I just want to tell you what I want. Below is the html code.
  containig different tags like &quot;em&quot; , and p and span.</p>
  <p>Classes are different , named as obisnuit and obisnuit2.</p>
  <pre><code>html1=&quot;&quot;&quot;&lt;p class=&quot;text_obisnuit2&quot;&gt;Best 3 developers.&lt;/p&gt;
          &lt;p class=&quot;text_obisnuit&quot;&gt;There are best three types of web developers in world.&lt;/p&gt;
          &lt;p class=&quot;text_obisnuit2&quot;&gt;&lt;em&gt;A javascript web developer.&lt;/em&gt;&lt;/p&gt;
          &lt;p class=&quot;text_obisnuit&quot;&gt;&lt;em&gt;A nodeJS web developer.&lt;/em&gt;&lt;/p&gt;
          &lt;p class=&quot;text_obisnuit&quot;&gt;&lt;em&gt;A python web developer &lt;span class=&quot;text_obisnuit2&quot;&gt;Django developer&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
  &quot;&quot;&quot;
  </code></pre>
  <p>I am trying to translate text between them and and inserting a translated version of text and I am successful at this thing, but the issue is coming in tags.</p>
  <p>Here is my code below: When I tried to scrape text using this method then the em tag was removed and only text was successfully inserted there.</p>
  <pre><code>from bs4 import BeautifulSoup
  import translators as ts
  soup1=BeautifulSoup(html1, 'html.parser')
  
  articles = soup1.find_all('p', {'class':&quot;text_obisnuit&quot;})
  for a in articles:  
  
      original_text=a.text
      #print(original_text)
      translated_output=ts.google(original_text, from_language='en', to_language='ro')
  
  
      a.string = translated_output.lower()
      print(a.string)
  
  
  
          
  </code></pre>
  <p>After running the above method, the output was:</p>
  <pre><code>OUTPUT&gt;&gt;
  
  &lt;p class =&quot; text_obisnuit2 &quot;&gt; Cei mai buni 3 dezvoltatori. &lt;/p&gt;
  &lt;p class = &quot;text_obisnuit&quot;&gt; Există cele mai bune trei tipuri de dezvoltatori web din lume. &lt;/p&gt;
  &lt;p class = &quot;text_obisnuit2&quot;&gt; Un dezvoltator web javascript. &lt;/p&gt;
  &lt;p class = &quot;text_obisnuit&quot;&gt; Un dezvoltator web nodeJS. &lt;/p&gt;
  &lt;p class = &quot;text_obisnuit&quot;&gt; Un dezvoltator web Python &lt;span class = &quot;text_obisnuit2&quot;&gt; Dezvoltator Django &lt;/span&gt; &lt;/p&gt;
  </code></pre>
  <p>If you see clearly, the em tag is removed from output, so I do not want it to be removed, I want the same html structure after translation.</p>
  <p>I also tried this method but only the text of em tag was scraped, not the whole html text.</p>
  <pre><code>articles = soup1.find_all('em')
  for item in articles:    
      original_text=item.text.strip()
      #print(original_text)
      translated_output=ts.google(original_text, from_language='en', to_language='ro')
      #print(item)
  
      item.string=translated_output
      
      
  </code></pre>
  <p>The OUTPUT I want should be:</p>
  <pre><code>OUTPUT&gt;&gt;
  
  &lt;p class =&quot; text_obisnuit2 &quot;&gt; Cei mai buni 3 dezvoltatori. &lt;/p&gt;
  &lt;p class = &quot;text_obisnuit&quot;&gt; Există cele mai bune trei tipuri de dezvoltatori web din lume. &lt;/p&gt;
  &lt;p class = &quot;text_obisnuit2&quot;&gt;&lt;em&gt; Un dezvoltator web javascript. &lt;/em&gt;&lt;/p&gt;
  &lt;p class = &quot;text_obisnuit&quot;&gt;&lt;em&gt; Un dezvoltator web nodeJS. &lt;/em&gt;&lt;/p&gt;
  &lt;p class = &quot;text_obisnuit&quot;&gt;&lt;em&gt; Un dezvoltator web Python &lt;span class = &quot;text_obisnuit2&quot;&gt; Dezvoltator Django &lt;/span&gt;&lt;/em&gt; &lt;/p&gt;
  </code></pre>
  <p>Anyone guide me, please.</p>