[RESOLVED] PHP cURL and DOMDocument - reading the page
ok, I am stumped... I am trying to grb info from a page.
the HTML source shows this
Code:
<span class='status' ng-hide='campaign.updating_worth > 0'>
{{ contestantEntries() }}
</span>
but the page displays a number (my current contest entries - yes I am a contest junkie! lol)
if i "Inspect Element" with Chrome I see
Code:
<span class="status ng-binding" ng-hide="campaign.updating_worth > 0">
5764
</span>
i want the 5764
I tried parsing with xpath as
Code:
$tags = $xpath->query('//*[@id="current-entries"]/span[1]');
gets a null
Code:
$tags = $xpath->query('//span[@class="status"]');
gets {{ contestantEntries() }} (plus other stuff)
I cant seem to get the actual value!
Code:
<span class="square-describe mont" id="current-entries">
<span class="status ng-binding" ng-hide="campaign.updating_worth > 0">
5764
</span>
I need that 5764 - im sure its possible!!
Re: PHP cURL and DOMDocument - reading the page
I sat here trying to think of a way to do it with nothing clean....
Can you do something with strpos() and just do a little math to figure out where that number is based on the begging and closing tags?
Like find the location of <span class="status ng-binding" ng-hide="campaign.updating_worth > 0">, then find the location of </span>. Then you know the number is between those two locations... Make sense?
Re: PHP cURL and DOMDocument - reading the page
Am afraid that the content inside that SPAN is being updated at client side using some Javascript code! So, when you do cURL, you are getting the html page with the Javascript code(keep in mind that Javascript code is executed only at the client side, ie. on the user's browser. Not on the server side!) in it. So even if you code to dig the contents of the SPAN using the strpos() function or some other techniques, you will still get the {{ contestantEntries() }} as value! You won't get the actual numeric value. Beavause the javascript code is not executed!
There are two workarounds that I can think of now:
1. Creating Browser Extension:
Creating a browser extension to do the parsing, if your project is just for your own use. Say, if your favorite browser is Google Chrome, you could create a chrome extension that will load up the url in a new tab/window and do the parsing live and store the results in local storage or submit it to some other page or do whatever you want. The advantage is that, the page that you wanted to parse will be opened up in your browser and then you are doing the parsing on this page after the javscript is also executed.
2. Using PhantomJS
Have a look at this answer: http://stackoverflow.com/questions/2...s-run-with-php
Btw, I have a small suggestion for you. You could edit your post and enclose those HTML code in CODE or HTML bbcode tag so that it will be displayed in a box like manner allowing better readability for the readers. :)
:wave:
Re: PHP cURL and DOMDocument - reading the page
ahhhh well that makes sense! so since its only updated after I (the client) receive it on my browser... PHP isnt seeing it.
well shoot. I will check out that phantom JS. Thanks!!