getButterfly Logo getButterfly code wrangling since 2005

I need to extract some data from a web page and place it on a fishing site. The source web page is updated frequently, and I don’t have the necessary time to update it. So, I’ll use the Javascript innerHTML function.

First of all, I should identify the element I’m trying to copy, let’s say a div with the ID info:

<div id="info">
This information updates daily.

The next step is to include the source web page as an IFRAME with width and height equal to 0:

<iframe name="thief" width="0" height="0" frameborder="0" src="source.html"></iframe>

The final code should read from the IFRAME and display the content on the destination page, in a specially created div:

<div id="destination">
This content will be replaced.

<script type="text/javascript">
// this script will copy the ontent of the 'info' div into the 'thief' div in the destination page
parent.document.all('thief').innerHTML = document.all('info').innerHTML;

Subscribe to getButterfly Blog

Once a week or so we send an email with our best content. We never bug you, we just send you our latest piece of content.

If you found any value in this post, agree, disagree, or have anything to add - please do. I use comments as my #1 signal for what to write about. Read our comment policy before commenting! Comments such as "Thank you!", "Awesome!", "You're the man!" are either marked as spam or stripped from URL.

6 thoughts on “Copy Web Page Content Using innerHTML

  1. I am feeling pretty slow here…cant seem to make this work. Where do you refernce the “destination” id in the code?

  2. The “destination” id should be a placeholder for the data you want copied.

    For example if you want to copy a sentence from another page on page x.html, you place the “destination” id div into x.html. Got it?

  3. Search Engines Parser is enormously fast, 100% automatic search engine results extractor you were dreaming about for many times. Search Engines Parser can extract results from all search engines at the same time, parse titles, descriptions and links automatically. You can specify which search engine(s) to use and what kind of data to parse. Search Engines Parser can output results to screen, export to MySQL database and write to CSV file.

Leave a reply

Love programming?

Learn about the most amazing things. Get smarter everyday!