Extract content showed by IFrame, saving it in database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Axirius
    New Member
    • Apr 2010
    • 3

    Extract content showed by IFrame, saving it in database

    Hi everybody,

    Asking for some help over here.

    My issue is that I´m looking how to copy or extract a particular table content of a website. I get the content from a external feed provider (Iframe format), the content is updated every minute. The Iframe updates new results and for instance, could show from 20 to 100 lines in the table in average at any moment.

    Since the information showed by the feed is dynamic, I can´t look for old results(e.g. last week, month, etc) Thus, my goal, (if it´s possible) have a script to read/copy the content within IFrame periodically (e.g twice a day) and it sends it to a MySQL database, within the hosting server. With this would be possible build a results history and be able to show old results
    of desired events in any moment when visitors want.

    The IFrame table shows something like this:

    Code:
    Country 1: Place
    04-12-2010 20:45 - cloudy - partly cloudy  Now    
    Country 2: Place
    04-12-2010 19:00 - cloudy - cloudy  Now
    .
    .
    .
    Country N: Place
    04-12-2010 17:30 - Sunny - Partly cloudy  Now
    In summary:
    It´s possible to extract/get the content that is within the table generated by IFrame, within the website where thw IFrame is showed?

    Many thanks for any advice or help with this.

    Best regards.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the content of an iframe is a website of its own.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      It may be easier to just pull the contents of the website being displayed in the <iframe> and parse it from there in PHP. You could use Curl or possibly just file_get_conten ts to pull the website, and then go through it with DOM or even SimpleXML. (Valid HTML can usually be parsed as XML)

      If you need to do this using the <iframe>, you would need to use JavaScript.

      Comment

      • Axirius
        New Member
        • Apr 2010
        • 3

        #4
        Hi and thanks both Atli and Dormilich for your answer,

        I´m newbie regarding web programming, actually the web I´ll trying to build is using Joomla, but I´ve learned some things about html, php so far in the process. But I don´t have enough knowledge yet to do this specific task on my own.

        I´ve followed information from links you gave me (php.net) and I´ve tried some example codes about "file" and "file_get_conte nt" functions, but I don´t know how to get the text content that is inside the IFrame which is seen by visitors. What I get is as follow:

        1 -) Using the following code with "file_get_conten ts" function, the script loads the entire site as I would surf its URL directly in web browser.

        Code using "file_get_conten ts" function:
        Code:
        <?php
        if( false == ($Content=file_get_contents( 'http://www.mywebsite.com' )))
            echo "Could not read file.";
          else
            echo "File contents: $Content";
        ?>

        2 -)
        Using the following code with "file" function, the script looks like loads the HTML code of the page, but in the part where I was expecting or which is supposed to show the text contained within IFrame, It only shows the IFrame Script. I mean:

        Code using "file" function:
        Code:
        <?php
        // Get a file into an array.  In this example we'll go through HTTP to get
        // the HTML source of a URL.
        $lines = file('http://www.mywebsite.com/');
        
        // Loop through our array, show HTML source as HTML source; and line numbers too.
        foreach ($lines as $line_num => $line) {
            echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";

        Result: HTML code, and only IFrame code.

        Code:
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
         <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb">
         <head>
        [B].
        .
        . [/B]
        [B]<iframe id="Iframe_title" frameborder="0" style="width:400px; height:150px;" src="/" allowtransparency="true"></iframe>
        <script type="text/javascript" src="http://www.source-of-iframe.com/js/Iframe_title.js?p=328&s=1&l=3&h=www.source-of-iframe.com"></script>[/B] 
        
        </div>
        [B].
        .
        .[/B]
        </body> 
        </html>
        Maybe somebody has done something similar before to give me some tips or a kind of example on how to follow.

        Many thanks in advance for any help.

        Best regards,

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          it may well be that the iframe only contains a script, which is responsible for creating the HTML content. in this case you can’t do anything about it, since PHP does not execute JavaScript.

          Comment

          • Axirius
            New Member
            • Apr 2010
            • 3

            #6
            Thanks Dormilich for reply,

            Well, if it not possible to extract the HTML content within the IFrame with PHP, how could be possible using javascript to run a script within some location inside the server?

            Is there some place where can I see similar examples regarding this?.

            I´ve searched in search engines without get what I´m looking for yet, maybe due I´m not using the correct word concepts or searching in the wrong programming language.

            Many thanks again.

            Best regards,

            Comment

            Working...