【发布时间】:2011-01-22 12:32:34
【问题描述】:
有这样的html
somehtml = "<p>Here is my solution: </p><pre><code> some code here </code> </pre> <pre>this is not a code</pre>"
通过python,我想将类“foo”添加到那些包含子<code> 的<pre> 标签中,因此我的输出将是:
somehtml = "<p>Here is my solution: </p><pre class="foo"><code> some code here </code> </pre> <pre>this is not a code</pre>"
我怎样才能做到这一点?
【问题讨论】:
-
您是在自己创建 HTML 吗?
-
是的,我通过 wmd 编辑器创建它以降价并在服务器级别转换为 html 和 google-code-prettify 语法突出显示,我需要在 pre 标签中添加“prettyprint”类