我正在分析StackOverflow的转储文件“Posts.Small.xml“使用pySpark。我想把一行中的“代码块”和“文本”分开。典型的解析行如下所示:
['[u"<p>I want to use a track-bar to change a form\'s opacity.</p>


<p>This is my code:</p>

<pre><code>decimal trans = trackBar1.Value / 5000;
this.Opacity = trans;
</code></pre>


<p>When I try to build it, I get this error:</p>

<blockquote>
 <p>Cannot implicitly convert type \'decimal\' to \'double\'.
</p>
</blockquote>

<p>I tried making <code>trans</code> a <code>double</code>, but then the control doesn\'t work.',
'", u\'This code has worked fine for me in VB.NET in the past.',
'\', u"</p>
 When setting a form\'s opacity should I use a decimal or double?"]']
我尝试过“itertools”和一些python函数,但是没有得到结果。 我提取上述行的初始代码是:
^{pr2}$任何想法都是感激的!在
您可以使用XPath提取
code
内容(使用lxml
库将有所帮助),然后选择其他所有内容来提取文本内容,例如:最简单的方法可能是对文本应用正则表达式,匹配标记“
' and '
”。这样你就可以找到代码块了。不过,你不会说你以后会怎么处理他们。所以。。。在相关问题 更多 >
编程相关推荐