how to use simple html dom get a div inner text

匿名 (未验证) 提交于 2019-12-03 01:29:01

问题:

innertext

Jow can I access innertext of divs not having class or id but span using simple html dom php parser? Thanks.

回答1:

If the styles are consistent, then you can loop over all divs in the document and filter them by style.

var divs = document.getElementsById("div");  for (var i = 0; i 


回答2:

You may use the content of style tag if no id or class is given there like:

include('simple_html_dom.php'); $html = file_get_html('http://www.mysite.com/'); foreach($html->find('div[style="float: left; margin-top: 10px; font-family: Verdana; font-size: 13px; color: #404040;"]') as $e) echo $e->innertext; 


回答3:

You could probably try to match some of their parents (which have class or id set), then traverse the DOM to the child you want.



回答4:

Thanks to all. I depends on simple_html_dom too much, Ben Blank give me a good way. And I also tried php regular-expression to match the div by myself.

preg_match_all('/([\d\D]*)/iU',$html,$match); print_r($match);  


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!