Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get info from another website from my HTML page?

What is needed is as follows:

I have an HTML webpage and I need to access another website and get something from its source code.

I want to run something like

link = "http://www.google.com";
doc.querySelectorAll('#courses_menu > ul > li > a'); // Apply on the link.

to get what I need from the link and use it!

However, I am using Jetpack slide bar.

Does it have to do anything with HTTP requests?

like image 701
msheshtawy Avatar asked Jan 23 '10 05:01

msheshtawy


2 Answers

I think you could pull the entire page using an Ajax request, put the content in a hidden iframe, and then manipulate the DOM in the iframe. Something like (here using the jQuery framework)

<iframe id="holder" style="display: none">

<script type="text/javascript">
$("#holder").load("http://www.google.com",function () {
  $link = $("#holder").contents().find("#courses_menu > ul > li > a");
});
</script>
like image 93
Jordan Reiter Avatar answered Oct 08 '22 01:10

Jordan Reiter


I recommend using a Ajax (e.g. jquery) with a PHP proxy on the same Webserver. The Proxy loads the the remote webpage and is then available under the same domain.

Don't forget to protect the proxy against abuse.

like image 35
Synox Avatar answered Oct 08 '22 01:10

Synox