我正在尝试使用 pyquery 1.2 从元素中获取一些文本。显示的文本中没有空格,但 pyquery 正在插入空格。
这是我的代码:
from pyquery import PyQuery as pq
html = '<h1><span class="highlight" style="background-color:">Randomized</span> and <span class="highlight" style="background-color:">non-randomized</span> <span class="highlight" style="background-color:">patients</span> in <span class="highlight" style="background-color:">clinical</span> <span class="highlight" style="background-color:">trials</span>: <span class="highlight" style="background-color:">experiences</span> with <span class="highlight" style="background-color:">comprehensive</span> <span class="highlight" style="background-color:">cohort</span> <span class="highlight" style="background-color:">studies</span>.</h1>'
doc = pq(html)
print doc('h1').text()
这会产生(注意冒号和句点前的空格):
Randomized and non-randomized patients in clinical trials :
experiences with comprehensive cohort studies .
如何停止 pyquery 在文本中插入空格?