Skip to content
Advertisement

I want to replace the html code with my own

I am using lxml and beautifulsoup library, actually my goal is to translate text of the specific tags out of the whole html code, what I want is, I want to replace the text of specific tags with the translated text.

I want to set a loop for the specific xpath in which all the translated text should be inserted one after another. And the html code should be returned with the translated version.

JavaScript

I am not getting the whole text from this xpath.

JavaScript

The output I am getting:

JavaScript

I want to extract all text of p tag of ” attribute class=obisnuit” using the above xpath and then translate it using translators library and want to return the whole html code with translated text between p tag of attribute class=obisnuit.

###NOTE:###

There should be a loop to insert the translated text in all these tags, I mean all tags should get its own text after translation using a loop.

I can not explain more, any one guide me please.

Advertisement

Answer

do you need to replace? Can’t you simply just set the string/contnet to the translation?

Also, you are sort of doing some unnecessary loops here. And you would need to fix your indentation as what you want is the for i,z to be 2 levels up.

try this:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement