Recently I became interested in a more convenient method to post to Yahoo clubs. Currently club members can recieve club posts via e-mail but to submit them requires visting the Yahoo web page. My goal was to enable club members to both post and recieve messages via e-mail. The first part toward achieving this goal was to set up a dedicated e-mail address on my mail server(sendmail on linux) with the following .forward file
"|/home/clubposter/process_post.pl"
where process_post.pl is the script which will parse the incoming e-mail and do the posting. Club members will send e-mail to this address and the contents of that e-mail will be the basis for the post. The format of the e-mail can be determined by the club members and the perl to parse it is left out of this CUFP submission to concentrate on the interesting part, namely, using perl to submit the post and programmatically navigating Yahoo Clubs. $url is obtained by doing a "view source" of the specific club's post submission page. $LOGIN, $PASSWD, $Subject, and $Post are from the incoming e-mail.
Here is the code which does the posting to Yahoo.
#!/usr/bin/perl -w #process_post.pl #A Yahoo club message poster. #Adam Russell(sail0r@creepjoint.net) #28 July 2001 use HTTP::Cookies; use HTML::Form; use LWP; #### #Now lets do the posting #0.)Login to yahoo #### $ua=new LWP::UserAgent; #Create a new user agent $ua->from('sail0r@creepjoint.net'); $url='http://post.clubs.yahoo.com/clubs/CLUBNAME/bbs?action=r;sid=CLUB +SID&tid=CLUBTID;mid=0'; #Create a login request $login_req = HTTP::Request->new(GET => $url); $login_res = $ua->request($login_req);#make the initial request.(to ge +t the cookies) $html = $login_res->content; #grab the resulting web page fro +m the request $form = HTML::Form->parse($html,$url);#Parse the content for the login + form $form->value('login',$LOGIN); #fill in the login form....... $form->value('passwd',$PASSWD); $req = $form->click; #and post it $res = $ua->request($req); #now yahoo wants to redirect. Make sure we...... $cookie_jar = HTTP::Cookies->new(); #create a cookie jar $cookie_jar->extract_cookies($res); #know what cookies yahoo needs.. +..... $goto = $res->header('location'); #where yahoo wants us to go..... +.. $new_req = HTTP::Request->new(GET => $goto);#generate a request to go +there....... $cookie_jar->add_cookie_header($new_req);#and let yahoo know we have t +heir cookies. $new_res = $ua->request($new_req); #engage!! #### # #1.)Now parse out the form returned from above in $new_res and do the +post #### $html = $new_res->content; $club_form = HTML::Form->parse($html,$url);#Parse the content for the +posting form $cookie_jar->extract_cookies($new_res); #get the cookies we need in + order to post $club_form->value('Subject',$Subject);#fill in the subject $club_form->push_input("textarea",{"name"=>"posting"});#create the "te +xtarea" for the post. $input = $club_form->find_input("posting","textarea"); #get a referenc +e to the textarea $input->value($Post); #fill the textarea in with the postin +g $req = $club_form->click; #create a request for the post $cookie_jar->add_cookie_header($req); #don't forget the cookies! +! $res = $ua->request($req); #engage!!