views:

48

answers:

2

Hi people,

I am trying to get this code working --

var loader;    
$(function() {    
    loader = new air.HTMLLoader();    
    loader.addEventListener(air.Event.COMPLETE, complete);    
    loader.load(new air.URLRequest('http://www.lilpirate.net/blog'));
});      
function complete() {   
    $(loader.window.document).ready(function(){
    $("#texts").val($("#header",loader.window.document).val());
    alert("Complete!");                                 
    });
}     

After compiling it using adl, the window opens and all goes as expected, but in the terminal I get the message

Error : Adobe Flash Player error: could not load cURL library

I get the Complete! alert message, but the textarea with id texts is not updated with the data in #header which is on http://www.lilpirate.net/blog

I think this is happening because of the error message adl is throwing.

I'm running Fedora 13 x64 and have installed flash player correctly(firefox test). I also have libcurl and libcurl-devel packages installed.

Help!

+2  A: 

You can achieve what you are trying to do (I think) without using the air HTMLLoader like this:

$(function() {    
    $.ajax({
        url: 'http://www.lilpirate.net/blog',
        success: complete,
        dataType: 'html'
    });
});
function complete( html ) { 
    var header = $(html).find('#header').html();
    $('#texts').html( header );
}     

SECURITY NOTE
I had better just say that this works because air will allow cross domain ajax requests. Air will also allow unrestricted access to the local filesystem. You need to be very carefull that you don't include any malicious scripts using this method.
You should definitely take steps to sanitise the response for example using dataFilter(data, type) to remove any script elements.

meouw
Actually I just want to screen scrape a page. So do not worry :-)
KPL
Thanks for the answer. That gave me an idea to achieve what I want to! Following is the exact code I am using to continue with screen scraping. Thanks a lot! :)
KPL
A: 

I worked around by using the following code to get the data in HTMLLoader.

This code alerts the html content of #header.

$(function() {    
    $.ajax({
          url: 'http://www.lilpirate.net/blog',
          success: callComplete,
          dataType: 'html'
    });
});
var loader;
function callComplete( html ) {                                                         
    loader = new air.HTMLLoader();                     
    loader.addEventListener(air.Event.COMPLETE, processComplete);                                
    loader.loadString(html);                           
}       
function processComplete() {
    var header = $('#header',loader.window.document).html();
    alert(header);
}

Hope this helps somebody.

KPL