www.webdeveloper.com
Results 1 to 7 of 7

Thread: HTML / iFrame / Id

  1. #1
    Join Date
    Jun 2011
    Location
    Grimsby
    Posts
    8

    Question HTML / iFrame / Id

    Hello

    I have a problem.

    I am looking to draw in information from another website into my website.
    The other website has this information within a table, I cannot edit the other site at all so can only get the information from it but wish to have parts of that information on my website. Its jst basic data.

    Im currently trying this with an iFrame. Heres an example of what I am doing:

    <iframe id="IDNAME" class="news-rss" src="URL HERE" this.getElementsByTagName('html')[0].id;><p>Your browser does not support iframes.</p></iframe>

    Is there anything im doing wrong or another way around this maybe not using iFrames? Please help? Thank you in advance.

    Ps. I have full consent to use the information on my website.

  2. #2
    Join Date
    Jun 2011
    Location
    Grimsby
    Posts
    8

    Help?!

    Does no one have a solution?

  3. #3
    Join Date
    May 2011
    Posts
    85
    Granted that my understanding is correct - I'd suggest you to see if that site offers some form of a RSS feed. There are plenty of dynamic RSS display scripts, which you can use to show within your site information from another site. The major benefit is the ability to customize it, rather than rely on whatever is in that iFrame.
    Start your website today at LiveCity

  4. #4
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    Use a screenscraper.
    What's the page? What's the content?

    Of course, you should have PHP to do this. Here are two ways to do it.

    PHP 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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Test of scrape</title>

    </head>

    <body>


    <?php 
    $page 
    file_get_contents("http://www.TARGET_URL_GOES_HERE.com");

    //Replace any stuff you don't want here...
    $page preg_replace('/<span/'"<!-- <span"$page); // This will make a span tag invisible.
    $page preg_replace('/<\/span>/'"<\/span> -->"$page); // This makes a closing span tag invisible.
    $page preg_replace('/<a /'"<a rel=\"nofollow\" "$page); // This makes all their hyperlinks nofollow



    $test explode('<table',$page);
    for(
    $t=1;$t<=count($test)-2;$t++){  // count how many closing table tags from the bottom you want and enter it here
     
    print "<table";
     print 
    $test[$t];
    }
    ?>
    print "</table>";
    </body>
    </html>
    Using cURL:
    PHP 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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Your Title</title>
    <base href="http://astore.amazon.com/gps-with-bluetooth-20?_encoding=UTF8&node=1"> <!-- This sets all links to the proper URL (optional) -->
    </head>
    <?php
    $url 
    "http://astore.amazon.com/gps-with-bluetooth-20?_encoding=UTF8&node=1";

    $ch curl_init();
    curl_setopt ($chCURLOPT_URL$url);
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
    curl_setopt ($chCURLOPT_PROXYTYPECURLPROXY_HTTP);
    curl_setopt ($chCURLOPT_PROXY,"http://64.202.165.130:3128");
    curl_setopt ($chCURLOPT_TIMEOUT120);
    $response curl_exec ($ch);
    if(
    is_int($response)) {
        die(
    "Errors: " curl_errno($ch) . " : " curl_error($ch));
    }
    curl_close ($ch);

    print 
    "$response";
    ?>



    </body>
    </html>

  5. #5
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    VERY SIMPLE SCREENSCRAPER:

    PHP Code:
    <?php

    $page 
    file_get_contents("http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html");
    // Replace the URL above with the one you want to scrape.


    // For you the $getpage should be the entire html you display on the page
    $explodefirst explode('<div class="forextable">',$page);   //Enter the starting piece of html you want to grab here... 
    $headerisgone $explodefirst[1];
    $explodesecond explode('</div>',$headerisgone); // Enter the ending piece of HMTL here
    $endresult $explodesecond[0];

    /*
    $endresult = str_replace('href="/','target="_blank" href="http://www.ecb.int/stats/exchange/eurofxref/html/', $endresult); // Makes links work in a new tab or window
    */


    print '<div class="forextable">'// Put back the starting HTML you grabbed...
    print $endresult;  //This prints your scrape
    print '</div>'// Put back the ending HTML here...
    ?>
    Now, say you want to put this on your page in an iframe.
    Copy the above and put it on your server in a file called, say:
    scrape.php

    Then either use PHP Include, or put that file into an iframe. PHP include is better as then search engines will find it and see it as content.

  6. #6
    Join Date
    Jun 2011
    Location
    Grimsby
    Posts
    8
    Thanks for the reply LiveCity and Donatello.
    The site doesn't have an RSS feed option. Donatello, those are great but I have gone with the iFrame option for now.

    Now I have a new problem. The site I am getting the data from automatically refreshes its page to update the information on the page constantly. When you are on my page with that showing up in the iframe, within seconds its refreshes to that site. Is there a way to keep it from not refreshing, reminding you that I cannot change anything on that site, but maybe something on my site where as I can have a bit of js that will stop it refrehing? any ideas, all new ideas welcome. Thank you in advance.

  7. #7
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    The ONLY way you can do all of that is by copying the page to your server with PHP, then putting that php page inside of your iframe.

    You can use that to strip out the Script tags and everything in between.

    Try it, then post back any problems you have with the script tags and we can help you fix it and make it look pretty.

    Simply copy my code and make a file as explained above. Replace my URL with yours and it will work!

    Good luck.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles