lov2code
lov2code

Reputation: 394

Getting html content from one page and adding it to my website

I have affiliated with expedia and I am using their API system. One of their requirements for launching the site is adding the terms and agreements to my page and they give us this page: http://travel.ian.com/index.jsp?pageName=userAgreement&locale=en_US&cid=xxx. I do not want to go to a different site, and I can not copy and paste the information because of updates. I also prefer not to use an iframe. Does anyone have any ideas on how to do this? Here is a webpage using this on their site with their domain: http://www.helloweekends.com/terms.htm. Does anyone know how they did this? Any help would be greatly appreciated!

Upvotes: 0

Views: 254

Answers (3)

Christofer Eliasson
Christofer Eliasson

Reputation: 33865

Since it originates from another domain, it wouldn't be possible to use JavaScript, due to the same origin policy. Also, relying on JavaScript for the update would be trouble for users who has JavaScript disabled, as they wouldn't see the terms. Since you don't want to use an iframe, or copy the content, I guess your best shot would be to scrape their page with a server-side language of your choice, and then display it on your page.

Scraping can be a bit tricky though, if you rely on their markup. If they change their markup, there is a chance that your script will break, thus stop updating the terms.

There are various tutorials available on how to scrape sites. Here are a few PHP examples:

  1. Web scrape with PHP
  2. PHP Screen Scraping Tutorial

Note Make sure that they allow you to scrape the page prior to implementing it, so that you don't violate their rules.

Upvotes: 1

faino
faino

Reputation: 3224

I would suggest the load() function offered by jQuery. It makes a simple AJAX call to retrieve a file, and you could even use a selector to only grab part of the page. For example, load the contents of a HTML page into a div:

$('#div_id').load('my_file.html');

Or just load a part of the page:

$('#div_id').load('my_file.html #main_text_id');

Upvotes: 0

Ricardo Souza
Ricardo Souza

Reputation: 16456

Do you know if their API serves something with JSON? A JSONP call can get the values to you, but it will make your page rely on javascript for the users to see the updated page.

Another option is to use PHP of any other server side language to get the contents of the url, process it and return the block you require.

Upvotes: 0

Related Questions