Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get html source code from external url

How can I get html source code from an external web page?

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

I've tried to get content of iframe using: $("#frame").contents().find("html");, but if in my case the webpage doesn't have html tags, just 1 line of text. I can't do it with php file_get_contents() because it doesn't keep session data.

like image 584
John Avatar asked Mar 13 '11 11:03

John


2 Answers

Cross domain? not possible without a server process. If you are on windows and can use HTA you can use the iframe

like image 89
mplungjan Avatar answered Oct 13 '22 00:10

mplungjan


With javascript, getting the file contents from another domain is not allowed in many browsers for security reasons. In php, you'd have to utilize curl.

For a workaround, you can make a php script with curl on your local domain and call that with javascript.

like image 33
dialer Avatar answered Oct 13 '22 01:10

dialer