[英]SimpleHTMLDOM finding a div with class
I am an inexperienced programmer with DOM. 我是DOM的经验不足的程序员。 I need to find out a div to remove it and all the content inside it.
我需要找出一个div来删除它以及其中的所有内容。 I have written the following code to get the div with class "name page_footer_container" .
我已经编写了以下代码来获取具有“ name page_footer_container”类的div。 When I m trying to output the finding to test if all is fine, I get following error.
当我尝试输出发现以测试是否一切正常时,出现以下错误。
__________________Code_________________________________________ __________________码_________________________________________
require_once('simple_html_dom.php');
$html = file_get_html($url);
$element=$html->find('div[class=page_footer_container]');
echo $element->outertext;
I get the following message with no result : Notice: Trying to get property of non-object. 我收到以下消息,但没有结果:注意:试图获取非对象的属性。
Would you please let me know what is the problem and what is the best strategy to remove a div with all of its content. 您能告诉我什么是问题,什么是删除具有所有内容的div的最佳策略?
This section of the page I want to remove : 我要删除的页面这一部分:
<div class="page_footer_container" >
<div class="page_footer_content">
<div class="page_footer_liner" ><hr class="page_footer_divider_above">
<div class="page_footer_text" ><a href="url">Click here to read our privacy policy.
<br>
Copyright © 2009-2012 mysite INc</a></div></div>
</div><div class="powered_by" >
<p><a rel="nofollow" href="#" target="_blank">
<img src="" border="0" alt=""></a><br><a rel="nofollow" href="" target="_blank"><strong>KKK</strong></a></p>
</div></div>
Thanks a lot 非常感谢
Try to get the div this way: 尝试以这种方式获取div:
$element=$html->find('div.page_footer_container');
With simple_html_dom you can search for elements using . 使用simple_html_dom,您可以使用来搜索元素。 for class and # for id.
用于类,#用于ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.