Python: Convert quote in HTML content not HTML tags -


i have piece of html this:

<pre class="script">template("main/globalshared");</pre> <pre class="script"> var link = '/draft/tracker_1.1'; if (wiki.pageexists(link)) {     &lt;div class="version"&gt; web.link(wiki.uri(link), 'version 1.1') &lt;/div&gt; } </pre> 

i need convert this:

<pre class="script">template(&quot;main/globalshared&quot;);</pre> <pre class="script"> var link = '/draft/tracker_1.1'; if (wiki.pageexists(link)) {     &lt;div class=&quot;version&quot;&gt; web.link(wiki.uri(link), 'version 1.1') &lt;/div&gt;  } </pre> 

i have been fiddling regular expressions can't seem close. think choice wrong.

can point me in right direction if possible?

use html parser instead, replace quotes .replace('"', '&quot;').

beautifulsoup makes task easy:

from bs4 import beautifulsoup  soup = beautifulsoup(htmlsource)  string in soup.strings:      string.replace_with(string.replace('"', '&quot;'))  htmlsource = str(soup) 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -