使用xpath删除<p>上的空格

时间:2016-01-17 08:30:57

标签: xml xpath google-sheets

我试图将文本放在<p>内的一堆<div>元素中 这就是我所拥有的:

=importXML(C2,"//div[contains(@class,'article-body')]/p/text()")

xpath可以在Google表格中正常工作并显示文字,但是会在Google表格上为每个<p>元素创建一个新行...每行都有一些文字。

有没有办法连接所有<p>元素中的所有文本,所以最后我只有一行包含所有文本?

以下是源代码:

<div class="article-body" itemprop="articleBody">

  <p>Believe the buzz: <a href="/tvshows/the-people-v-o-j-simpson-american-crime-story/705835/"><em>The People v. O.J. Simpson: American Crime Story</em></a><em> i</em>s really good - like, edge-of-your-seat, a little bit outrageously good.</p>

  <p><strong>1. It's still an emotionally loaded story, 25 years later. </strong>While shooting the series, <a href="/celebrities/cuba-gooding-jr/213507/">Cuba Gooding Jr.</a>, who plays O.J. Simpson, was reunited with John Singleton, who not only directs
    an episode but is the only one among them who'd met and talked with O.J. "The first time I worked with ing."</p>

  <p><em>American Crime Story: The People v. O.J. Simpson</em> premieres Tuesday, Feb. 2 at 10/9c on FX.</p>
</div>

这就是Google Chrome浏览器的外观:

<div class="article-body" itemprop="articleBody">
::before
  <p>...</p>
  <p>...</p>
  <p>...</p>
  <p>...</p>
  <p data-section="sharethrough"></p>
  <div data-placement="articles.show.sharethrough.inline" id="native_top" class="ad-dfp"></div>
  <p>...</p>
  <p>...</p>
  <p>...</p>
  <p>...</p>
::after
 </div>

1 个答案:

答案 0 :(得分:1)

这是有效的 - 它被分解的部分原因有两个 - 你抓住每个p元素而不是整个块 - 并且当你可以像这样抓住整个div时也说它包含p:

=IMPORTXML("http://www.tvguide.com/news/the-people-vs-oj-simpson/","//*[@class='article-body']")

或者如果您希望所有问题都集中在一个单元格中:

=concatenate(IMPORTXML("http://www.tvguide.com/news/the-people-vs-oj-simpson/","//*[@class='article-body']"))