Results 1 to 4 of 4

Thread: [RESOLVED] PHP cURL and DOMDocument - reading the page

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Resolved [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 &gt; 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!!
    Last edited by Static; Jun 12th, 2015 at 07:36 AM.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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?
    My usual boring signature: Something

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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!!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width