解析锚标记的html文档

时间:2014-11-30 05:43:47

标签: php

说我有

<a href="www.myurl/point.html" class="l" style="color:#436DBA;" onclick="return rs(this,'8 Stunning Linguistic Miracles of The Holy Quran | Kinetic Typography 144p (Video Only).mp4');">&raquo; Download MP4 &laquo;</a> - <b>144p (Video Only)</b> - <span> 19.1</span> MB<br />
像这样的html页面我想用简单的dom php解析器解析它,我想下载mp4 114p 19.1作为输出,而我尝试此代码

foreach($displaybody->find('a ') as $element) {
       // echo $element->innertext . '<br/>';

它还给我下载mp4我怎么解析剩余值下载mp4 114p 19.1请帮帮我

1 个答案:

答案 0 :(得分:0)

您不能再使用<a>标记了,因为您尝试访问的某些文字不再包含在其中,定位文档本身然后使用{{1 }}:

->plaintext

以下是使用xpath访问每行$html = <<<EOT <a href="www.myurl/point.html" class="l" style="color:#436DBA;" onclick="return rs(this,'8 Stunning Linguistic Miracles of The Holy Quran | Kinetic Typography 144p (Video Only).mp4');">&raquo; Download MP4 &laquo;</a> - <b>144p (Video Only)</b> - <span> 19.1</span> MB<br /> EOT; $displaybody = str_get_html($html); echo $displaybody->plaintext; 的另一种方法:

DOMDocument

Sample Output