1

I've seen so many questions about scraping html with Jquery + node.js + YQL. It makes no mention of getting the css and javascript from the webpage.

Is there any way to get the html, css and javascript of an external website without using server side techniques?

*I need this to happen in code so I can use the results in a webapp.

4
  • Right Click, Save Page As... Commented Feb 12, 2013 at 5:05
  • Thanks for pointing that out, I will edit to specify. Commented Feb 12, 2013 at 5:06
  • What kind of information you want to retrieve ? Commented Feb 12, 2013 at 9:51
  • The html, css and javascript of the site. Commented Feb 12, 2013 at 17:00

1 Answer 1

0

Possible Duplicate of this. Your answer lies here.

You should check out jQuery. It has a rich base of AJAX functionality that can give you the power to do all of this. You can load in an external page, and parse it's HTML content with intuitive CSS-like selectors.

An example using $.get();

$.get("anotherPage.html", {}, function(results){
  alert(results); // will show the HTML from anotherPage.html
  alert($(results).find("div.scores").html()); // show "scores" div in results
});

For external domains I've had to author a local PHP script that will act as a middle-man. jQuery will call the local PHP script passing in another server's URL as an argument, the local PHP script will gather the data, and jQuery will read the data from the local PHP script.

$.get("middleman.php", {"site":"http://www.google.com"}, function(results){
  alert(results); // middleman gives Google's HTML to jQuery
});

Note: PHP thing is for different domains.

Sign up to request clarification or add additional context in comments.

1 Comment

sorry for not specifying. I want to retrieve the info on an external site with only javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.