By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,963 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,963 IT Pros & Developers. It's quick & easy.

Extract content showed by IFrame, saving it in database

P: 3
Hi everybody,

Asking for some help over here.

My issue is that Im 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 cant look for old results(e.g. last week, month, etc) Thus, my goal, (if its 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:

Expand|Select|Wrap|Line Numbers
  1. Country 1: Place
  2. 04-12-2010 20:45 - cloudy - partly cloudy  Now    
  3. Country 2: Place
  4. 04-12-2010 19:00 - cloudy - cloudy  Now
  5. .
  6. .
  7. .
  8. Country N: Place
  9. 04-12-2010 17:30 - Sunny - Partly cloudy  Now
In summary:
Its 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.
Apr 19 '10 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 5K+
P: 8,639
the content of an iframe is a website of its own.
Apr 19 '10 #2

Expert 5K+
P: 5,058

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_contents 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.
Apr 19 '10 #3

P: 3
Hi and thanks both Atli and Dormilich for your answer,

Im newbie regarding web programming, actually the web Ill trying to build is using Joomla, but Ive learned some things about html, php so far in the process. But I dont have enough knowledge yet to do this specific task on my own.

Ive followed information from links you gave me ( and Ive tried some example codes about "file" and "file_get_content" functions, but I dont 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_contents" function, the script loads the entire site as I would surf its URL directly in web browser.

Code using "file_get_contents" function:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if( false == ($Content=file_get_contents( '' )))
  3.     echo "Could not read file.";
  4.   else
  5.     echo "File contents: $Content";
  6. ?> 

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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Get a file into an array.  In this example we'll go through HTTP to get
  3. // the HTML source of a URL.
  4. $lines = file('');
  6. // Loop through our array, show HTML source as HTML source; and line numbers too.
  7. foreach ($lines as $line_num => $line) {
  8.     echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";

Result: HTML code, and only IFrame code.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
  2.  <html xmlns="" xml:lang="en-gb" lang="en-gb">
  3.  <head>
  4. .
  5. .
  6. <iframe id="Iframe_title" frameborder="0" style="width:400px; height:150px;" src="/" allowtransparency="true"></iframe>
  7. <script type="text/javascript" src=""></script> 
  9. </div>
  10. .
  11. .
  12. .
  13. </body> 
  14. </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,
Apr 19 '10 #4

Expert Mod 5K+
P: 8,639
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.
Apr 19 '10 #5

P: 3
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?.

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

Many thanks again.

Best regards,
Apr 19 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.