views:

53

answers:

2

Hello all,

I am making use of the PHP Simple HTML DOM Parser to get the number 3869 from a HTML page. I tried this and a few other variations.

foreach($html->find('span[class=searchresults_tab_number]') as $element) {
            echo $element->innertext . '<br />';
}

But I keep getting nothing returned! All I need is the number from set1, how can I match this?

<div class="local-tabs">
    <div class="local-tab active">Set1 <span class="searchresults_tab_number">(3869)</span></div>
    <div class="local-tab"><a href="#">Set2 <span class="searchresults_tab_number">(1)</span></a></div>
    <div class="local-tab"><a href="#">Set3 <span class="searchresults_tab_number">(3870)</span></a></div>
</div>

Thanks all for any help

Update

I just realised that those elements are created via javascript, does this make a difference?

tabs.insert("<div class='local-tab active'>Set1 <span class='searchresults_tab_number'>(3869)</span></div>");
A: 

http://gist.github.com/488815

The above gist seems to be working fine, I get the output one would expect. Could it be something wrong with the code before it? Do you have a more complete sample?

In reply to updated question: I'm very confused as to what you're doing... where does PHP gets its DOM from? If the divs are created in Javascript, PHP won't know about them. It does not execute the javascript that is part of HTML content.

kander
The php parser is separate to the HTML page it is parsing. So my PHP parser makes use of a `file_get_html` so the html page is loaded and then it tries to parse it, but the html page makes use of Javascript to create some elements which I would of thought the parser should have access to.
Abs
if the javascript is on the page (as opposed to a script include), php has access to the javascript on the page, yes. But as arbitrary text. php doesn't actually execute the javascript on the page, so the div is never built. The php DOM is a static DOM, not a live DOM. So if the javascript is physically on the page, you can use regex to parse out the raw info you need.
Crayon Violent
+1  A: 

javascript is not executed when scraping a page, so php cannot scrape for it if it is being generated with javascript. javascript is executed by the browser.

Crayon Violent
@Crayon, that is the problem thanks.
Abs