innertext
Jow can I access i
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
}
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('/<div.*(style="float: left; margin-top: 10px; font-family: Verdana; font-size: 13px; color: #404040;").*>([\d\D]*)<\/div>/iU',$html,$match);
print_r($match);
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;
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.