1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to get information hidden by javascript?

Discussion in 'PHP & Perl' started by Kingfresh, Mar 14, 2010.

  1. Kingfresh

    Kingfresh Regular Member

    Joined:
    Jul 8, 2009
    Messages:
    374
    Likes Received:
    295
    Hey guys,

    i need your help, i tried with java but didn't worked.... so i have a website that hides information behind a button (like a spolier) but it isnt a real spolier because it is text that you have click to ... like "Click me" than information is shown, anyway is there a solution to get this peace of information using php?

    thanks!
     
  2. pyronaut

    pyronaut Executive VIP

    Joined:
    Dec 9, 2008
    Messages:
    1,229
    Likes Received:
    1,422
    You will need to use Javascript. I don't quite understand how PHP can help you in this case. PHP isn't really a "presentation" language.

    If you want hidden elements. What you need to do is have their style (CSS style) set to "display:hidden". And then create an onclick event handler with javascript that does

    getElementById('YourDivID').style.display="inline";

    This will do just a straight show. There wont be any fancy fade effects or drop downs. But it works.

    If you want straight Javascript on it. Check out something like this : http://dhtmlpopups.webarticles.org/fade-effects.php

    Otherwise you can go have a look at other library's like jQuery etc.
     
    • Thanks Thanks x 1
  3. wowhaxor

    wowhaxor Executive VIP Premium Member

    Joined:
    Apr 28, 2007
    Messages:
    2,021
    Likes Received:
    3,353
    Location:
    ?¿?
    Home Page:
    I have something similar and that's exactly what I do.
     
  4. BozoClown

    BozoClown Junior Member

    Joined:
    Jan 4, 2009
    Messages:
    150
    Likes Received:
    106
    If you want to write a script that scrapes the site, there could be a way.

    If the javascript just "unhides" the information, you can parse the source and read whatever was being hidden.

    On the otherhand if the JS makes an ajax call and inserts the reply into the page, you will have to parse the page source, grab the variables being sent via ajax, then make the xmlhttprequest in PHP.
     
  5. pyronaut

    pyronaut Executive VIP

    Joined:
    Dec 9, 2008
    Messages:
    1,229
    Likes Received:
    1,422
    Woah, OP, did you edit your post? Im 99% sure you never said that you didn't say scraping in the original post. You said you needed to hide content, Meh. Anyway...

    For scraping content via PHP the easiest way will just be using CURL.

    PHP:
    <?php
            
    // create curl resource
            
    $ch curl_init();

            
    // set url
            
    curl_setopt($chCURLOPT_URL"example.com");

            
    //return the transfer as a string
            
    curl_setopt($chCURLOPT_RETURNTRANSFER1);

            
    // $output contains the output string
            
    $output curl_exec($ch);

            
    // close curl resource to free up system resources
            
    curl_close($ch);     
    ?>
    Stolen from http://www.php.net/manual/en/curl.examples-basic.php

    There is better examples out there. But this does the basics. Generally speaking, Bozoclown is right. The spoiler will be in the source, and the button just shows it. Infact probably exactly how i explained in my first post.