[英]How to exclude a certain class in fetching contents from a webpage?
I'm using SIMPLE_HTML_DOM as my parser. 我正在使用SIMPLE_HTML_DOM作为解析器。
So here's the thing I've already get the contents using a certain div with class, but that div has a child div that are unnecessary that I don't want to get when I run the parser. 所以这是我已经使用带有类的某个div来获取内容的东西,但是该div有一个子div,在运行解析器时我不想得到它。
$main_body = $html->find('div[class=storypage-divider desktop]', 0)->plaintext;
echo $main_body;
You can select the child element that you do not want and delete it. 您可以选择不需要的子元素并将其删除。
$main_body = $html->find('div[class=storypage-divider desktop]', 0);
$main_body->find('div[class=do-not-want]', 0 )->outertext = '';
echo $main_body->plaintext;
Note: I did not test this code!, and change the class name "do-not-want" 注意:我没有测试此代码!,并更改了类名“ do-not-want”
Hope that helped. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.