想要获取p标签内的内部文本

时间:2012-09-26 13:26:49

标签: php simple-html-dom

网站html是这样的,我希望使用curl嵌入代码。

概念

<div id="postdiscriptiontext">
<p>
<embed src="http://videobb.com/e/swLN6oRlzFby" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="540" height="599"/>
</p>
</div>
I tried like this
 $html = str_get_html($links);
        echo $html->find('div.postdiscriptiontext p')->innertext . '<br>';

这是我正在犯的错误 注意:尝试在第96行的C:\ xampp \ htdocs \ anicravefinal \ viewanimevideo.php中获取非对象的属性

2 个答案:

答案 0 :(得分:2)

$Content = '<div id="postdiscriptiontext">
<p>
<embed src="http://videobb.com/e/swLN6oRlzFby" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="540" height="599"/>
</p>
</div>';
preg_match_all('|<p>(.*?)</p>|',$Content,$Output);
print_r($Output);

使用此 如果你想要你可以尝试

$Content = file_get_contents('URL OF PAGE THAT YOU WANT TO GRAB');

答案 1 :(得分:0)

试试这个

    <?php
    $html = '<div id = "postdiscriptiontext">
                <p>
                    <embed src = "http://videobb.com/e/swLN6oRlzFby" type = "application/x-shockwave-flash" allowscriptaccess = "always" allowfullscreen = "true" width = "540" height = "599"/>
                </p>
            </div>';

    $doc = new DOMDocument();
    $doc->loadXML($html);
    $myHtml = $doc->getElementsByTagName("p");
    $myHtml = $myHtml->item(0)->nodeValue;
    ?>