Skip to content Skip to sidebar Skip to footer

How Can Chrome Extensions Basically Curl Other Pages?

I'm thinking about writing a Chrome extension that will need to, on a certain dynamic page of a certain site, grab a few links and analyze the contents of the linked pages. I actua

Solution 1:

Use jquery ajax to fetch the content of other pages.

Solution 2:

You can use jQuery and this plugin by James Padolsey to make a cross domain request; the plugin will return the page contents. You can then do something like this to get it into a jQuery object:

$.ajax({
    url: 'http://example.com',
    type: 'GET',
    success: function(res) {
        var contents = $(res.responseText);
    }
});

With that contents object you can do anything you would do normally with a jQuery object, such as find(). For instance, if you wanted to get the title of the page, you could do:

$.ajax({
    url: 'http://example.com',
    type: 'GET',
    success: function(res) {
        var contents = $(res.responseText);
        var title = contents.find('title').text();
    }
});

Post a Comment for "How Can Chrome Extensions Basically Curl Other Pages?"