开发者

Need help with curl post and javascript

I'm trying to log in to some web site. I did it before with some other site but this site is more complicated. I used LIVE HTTP Headers to capture the post request. I noticed that the post request was done correctly but from some reason I'm not being transferred to the correct url. I went over the page source and I think this form is being transferred using JS.

This is what appended to the post arguments after the __VIEWSTATE variable:

&ctl00_Menu_MainMenu_ContextData=&ctl00%24middleContent%24TextBoxName=0526579737&ctl00%24middleContent%24TextBoxPass=LIRAN&ctl00%24middleContent%24TextBoxPriv=liran&ctl00%24middleContent%24CheckLicense=on

and this is the javascript function that validates this info:

function Continue_Click()
    {
        var LabelError = document.getElementById('ctl00_middleContent_LabelError');
        var lnkButton1 = document.getElementById(middleContent + 'lnkButton1');
        var msg = validateLoginPeleNumRecognizeUser(document.getElementById('ctl00_middleContent_TextBoxName').value);
        if (msg == '')
        {
            if (validateLoginPeleNumEmail(document.getElementById('ctl00_middleContent_TextBoxName').value)){
                musixMail = document.getElementById('ctl00_middleContent_TextBoxName').value;
                var obj = document.getElementById('ctl00_middleContent_TextBoxPriv');
                if (obj != null && obj.value != '')                    
                    msg = validateLoginUserLogin(obj.value);

                if (msg == '')  
                {                        
                    if(document.getElementById('ctl00_middleContent_CheckLicense').checked)
                    {
                        if(log.login('recognize'))
                        {
                            __doPostBack('ctl00$middleContent$lnkButton1','');
                        }
                    }
                    else
                        LabelError.innerHTML = 'עליך להסכים לתנאי השימוש על מנת להמשיך לגלוש באתר';
                }
                else
                    LabelError.innerHTML = msg;
            }
            else{
                msg = validateLoginPasswordLogin(document.getElementById('ctl00_middleContent_TextBoxPass').value);
              开发者_StackOverflow  if (msg == '')    
                {
                    var obj = document.getElementById('ctl00_middleContent_TextBoxPriv');
                    if (obj != null && obj.value != '')                    
                        msg = validateLoginUserLogin(obj.value);

                    if (msg == '')  
                    {                        
                        if(document.getElementById('ctl00_middleContent_CheckLicense').checked)
                        {
                            if(log.login('recognize'))
                            {
                                __doPostBack('ctl00$middleContent$lnkButton1','');
                            }
                        }
                        else
                            LabelError.innerHTML = 'עליך להסכים לתנאי השימוש על מנת להמשיך לגלוש באתר';
                    }
                    else
                        LabelError.innerHTML = msg;
                }   
                else
                    LabelError.innerHTML = msg;
            }
        }
        else
            LabelError.innerHTML = msg;
    }        
    $(function(){
        $('#ctl00_middleContent_TextBoxName,#ctl00_middleContent_TextBoxPass,#ctl00_middleContent_CellName').keypress(function(e){
            if(e.keyCode==13)                
                Continue_Click();
        });

Does anyone know how can I trigger this function when using curl?

Thanks


Curl is just a tool to make HTTP requests to a server, and (optionally) record the response. When you make the request you're thinking about, the server sends a few KB of text in response to curl's request.

In this case, the text is HTML with some Javascript embedded (or referenced). But curl doesn't know how to parse the HTML, because it's just a data-transfer tool. It received the data - job done.

So I think you're going to hit a dead end if you want to have curl automatically execute the Javascript. You'd need a JS engine to do this, as well as an HTML engine to parse the HTML and work out what JS commands should be actually run. Rhino or Spidermonkey could do the former, but since you don't have a JS file but an HTML file this won't work too well. Fundamentally, if you want this to work generally, comprehensively and autonomously, you'll need a tool that behaves identically to a browser - which, by definition, is a browser.

In most cases, if you're looking at a single site though, you can work out the request that curl needs to send by sniffing the requests made by a browser. Typically, in the worst case scenario you might need to use a regex on the returned text to extract e.g. the sessionID; for a given site this isn't so bad. If you're not prepared to have this level of brittleness, then curl is quite simply not an appropriate tool for what you're doing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜