【问题标题】:How get previousSibling and nextSibling如何获取 previousSibling 和 nextSibling
【发布时间】:2011-10-27 20:06:09
【问题描述】:

我有html:

<hr>
<p><font face="AvantGarde Bk BT" style="font-size: 9pt" color="#66FF33">
(08/04/2006) Parallel Worlds are one of the featured artists in the
<a href="http://www.urband.net/radio/">Urban D radio</a>. there you can listen 
to many tracks from the 3 released cd albums.</font></p>
<hr>

我需要得到

1:(08/04/2006) Parallel Worlds are one of the featured artists in the

2:. there you can listen to many tracks from the 3 released cd albums.

我使用http://simplehtmldom.sourceforge.net

我得到元素 $e-&gt;href 这是&lt;a href="http://www.urband.net/radio/"&gt;Urban D radio&lt;/a&gt;

【问题讨论】:

  • $font_content = preg_match('/&lt;font face="AvantGarde Bk BT"[^&gt;]*&gt;([\s\S]+?)&lt;/font&gt;/', html) $text = preg_replace('/&lt;a[^&gt;]+&gt;[^&lt;]*&lt;/a&gt;/', '', $font_content)
  • @Aamir Adnan,不!我刚让自己不要使用正则表达式

标签: php html-parsing web-scraping


【解决方案1】:

【讨论】:

  • 胡?您问如何获取 previousSibling 和 nextSibling,它在我链接的页面上说明了如何获取。
  • 我需要前后各 50 个字符
  • 使用文档中的代码获取整个节点,然后对结果使用子字符串函数将其修剪为 50 个字符。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-13
  • 2014-01-13
  • 1970-01-01
  • 1970-01-01
  • 2018-10-21
  • 2011-08-25
相关资源
最近更新 更多