如何使用简单的html dom获取div内部文本 [英] how to use simple html dom get a div inner text
本文介绍了如何使用简单的html dom获取div内部文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div style="float: left; margin-top: 10px; font-family: Verdana; font-size: 13px; color: #404040;">innertext</div>
我可以访问没有 class
或 id
但 span
使用简单的html dom php解析器?谢谢。
Jow can I access innertext of divs not having class
or id
but span
using simple html dom php parser? Thanks.
推荐答案
如果样式是一致的,那么您可以循环遍历文档中的所有div,并按样式过滤。 / p>
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 < divs.length; i++) {
var div = divs[i];
// skip the current div if its styles are wrong
if (div.style.cssFloat !== "left"
|| div.style.marginTop !== "10px"
|| div.style.fontFamily !== "Verdana"
|| div.style.fontSize !== "13px"
|| div.style.color !== "#404040") continue;
var text = div.innerText || div.textContent;
// do something with text
}
这篇关于如何使用简单的html dom获取div内部文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文