How to get html source code from external URL

How can I get html source code from an external webpage?

Something like: getHtml('http://google.com'); .

I tried to get the contents of the iframe using: $("#frame").contents().find("html"); but if in my case the web page does not have html tags, only 1 line of text. I cannot do this with php file_get_contents() because it does not save session data.

+7
source share
3 answers

Cross domain? impossible without a server process. If you are in windows and can use HTA, you can use iframe

+8
source

Using javascript, retrieving the contents of a file from another domain in many browsers is prohibited for security reasons. In php you will need to use curl .

For a workaround, you can make a php script with curl in your local domain and invoke it using javascript.

+2
source

I think using javascript xmlhttprequest with setRequestHeader ('content-type', 'xml / text') and url what you need, it will return responseText as an html page

-one
source

All Articles