Reputation: 57986
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
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>");
Upvotes: 0
Views: 898
Reputation: 32537
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.
Upvotes: 2
Reputation: 4306
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.
Upvotes: 0