What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help] dealing with cookies

[Help] dealing with cookies
Author: Message:
BstrdSmkr
Junior Member
**

Avatar
Earned. Never Given.

Posts: 46
39 / Male / –
Joined: Jul 2006
O.P. Dodgy  [Help] dealing with cookies
anybody have any ideas about dealing with cookies from websites? I'm working on a page scrapper for a myspace.com account and it's looking like i may need to deal with cookies.  what i've got in mind is scraping the page contents for "setCookie" and etc, then dumping that into a text file and reading it back when necessary, but that seems pretty heavy for at 3 bit crumb : \  anyone have any better ideas/expierence? 
07-14-2006 01:39 AM
Profile E-Mail PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: [Help] dealing with cookies
It shouldnt be that hard Im guessing your trying to login so in my example ill do a post request then get the cookie header


this example should log you onto this forum and show all Trashing and testing threads (which you need to be logged in to see)
code:
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var cookies;

login("username", "password", getTandT);


function getTandT(){
    xmlhttp.open("GET", "http://shoutbox.menthix.net/forumdisplay.php?fid=18", true);
    xmlhttp.setRequestHeader("Cookie" , cookies.join(";") )
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState==4) {
            if(xmlhttp.status == 200){
                //look its T and T's source :D
                //Debug.Trace(xmlhttp.responseText);
               
                //show all threads
                var threads = xmlhttp.responseText.match(/<a href="showthread.php\?tid=([0-9]+)">([^<]*)<\/a>/g);
                for(var i=0;i<threads.length;i++){
                    Debug.Trace(threads[i].match(/<a href="showthread.php\?tid=([0-9]+)">([^<]+)<\/a>/)[2])
                }
            }
        }
    }

    xmlhttp.send();

}


function login(username , password , callback){
    xmlhttp.open("POST", "http://shoutbox.menthix.net/member.php", true);
    //set the request header for post
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   
   
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState==4) {
            if(xmlhttp.status == 200){
                cookies = get_cookies(xmlhttp.GetAllResponseHeaders());
                callback();
            }
        }
    }
   
    xmlhttp.send("username=" + escape(username) + "&password=" + escape(password) + "&action=do_login");
}



//sometimes the Set-Cookie header is sent twice and getResponseHeader only reads the first... so we have to join it ourselfs :(
function get_cookies(headers){
    var header = headers.split("\r\n");
    var cookies = [];
    for(var i=0;i<header.length;i++){
        var type = header[i].match(/^Set-Cookie: (.*)$/);
        if(type){
            cookies.push(type[1]);
        }
    }
    return cookies;
}


[Image: dt2.0v2.png]      Happy Birthday, WDZ
07-14-2006 07:25 AM
Profile PM Web Find Quote Report
BstrdSmkr
Junior Member
**

Avatar
Earned. Never Given.

Posts: 46
39 / Male / –
Joined: Jul 2006
O.P. RE: [Help] dealing with cookies
thanks for your help, worked like a charm!  unfortunately, after all that, it turns out that i was smoking crack and didn't need it anyway >.<
07-17-2006 03:56 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On