Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,664 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,160 people online right now. Registration is fast and FREE... Join Now!




perl gmail getting script

 
Reply to this topicStart new topic

perl gmail getting script, I need a small ammount of help getting my gmail with perl

x1101
post 18 Aug, 2008 - 09:12 PM
Post #1


New D.I.C Head

*
Joined: 26 Nov, 2007
Posts: 20


My Contributions


I am working on a perl script that will login to gmail, and display on my unread email
I have the login part working flawlessly, and I have found out how the emails are distinguished.
In the HTML of gmail, the only difference between an unread mail and a read mail is that <tr> it is in has a different bgcolor

since unread mail is grouped together I thought starting at the 'unread' mail color background and matching up to the 'read' mail background color would be slick, no dice

So I guess the only line I am having issues with is this:
CODE

my @test = $output =~ m|\Q(<tr bgcolor="#ffffff">.*)<tr bgcolor="#E8EEF7">\E|g;


for some reason this does not match everything start with the bgcolor or 'unread' and going to 'read'

Thanks in advance

CODE

#!/usr/bin/perl

##Use##
use strict;
use WWW::Mechanize;

##Declarations##
my $url = "http://gmail.com";
my $outfile = 'gm-out.html';
my $mech = WWW::Mechanize->new(autocheck =>1);

##Let the code Begin##
open(OUTFILE, ">$outfile" );
$mech->get($url );

##################Login##########################
$mech->form_number(1);                #
$mech->field('Email', 'MYUSERNAME');        #
$mech->field('Passwd', 'MYPASSWORD');        #
$mech->click();                    #
$mech->follow_link( n=>1 );            #
#################################################
#the last line follows the auto re-direct



my $output = $mech->content();
#my $test = $te->parse( $output );

my @test = $output =~ m|\Q(<tr bgcolor="#ffffff">.*)<tr bgcolor="#E8EEF7">\E|g;
foreach my $test (@test)
{
    print OUTFILE $test;
}
close OUTFILE;
User is offlineProfile CardPM

Go to the top of the page

x1101
post 19 Aug, 2008 - 07:44 AM
Post #2


New D.I.C Head

*
Joined: 26 Nov, 2007
Posts: 20


My Contributions


Sorry for the post, i have since fixed this. And because I always get annoyed when people do this and then don't post HOW they fixed it,

CODE

my @test = $output =~ m|(<tr bgcolor="#ffffff">.*?<b>.*?&nbsp;.*?</b>)|gs;


I turned off greedy matching, (the ?'s after the .*) and changed my end string to the end of the section. this works quite nicely now

This post has been edited by x1101: 19 Aug, 2008 - 07:45 AM
User is offlineProfile CardPM

Go to the top of the page

KevinADC
post 19 Aug, 2008 - 08:17 PM
Post #3


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 213



Thanked 3 times

Dream Kudos: 50
My Contributions


You also removed the \Q..\E sequence, which was killing the meta meaning of the capturing parenthesis in the regexp. \Q escapes everyting except $ and @, so the parenthesis are treated literally instead of as meta characters.
User is offlineProfile CardPM

Go to the top of the page

x1101
post 19 Aug, 2008 - 09:55 PM
Post #4


New D.I.C Head

*
Joined: 26 Nov, 2007
Posts: 20


My Contributions


Thanks, thats good to know. I haven't really done much in perl, especially with regex, but this seemed like a fun idea. While doing it, I did notice that the \Q and the \E were messing it up a bit, but didn't really think of it at the time. For reference and for anyone who stumbles upon this later, how do you include \Q and the following \E to do something like this and still get the capture of the ()?
User is offlineProfile CardPM

Go to the top of the page

KevinADC
post 19 Aug, 2008 - 10:14 PM
Post #5


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 213



Thanked 3 times

Dream Kudos: 50
My Contributions


You can't. You could move the \ Q and \E to inside the parenthesis though.
User is offlineProfile CardPM

Go to the top of the page

homemade-jam
post 20 Aug, 2008 - 04:05 AM
Post #6


eeeAddict

Group Icon
Joined: 17 Mar, 2008
Posts: 1,044



Thanked 1 times

Dream Kudos: 25
My Contributions


WWW::mechanize is really nice...I recently did a similar project for outlook web access accounts..it only checked to see if there were new mesages, haven't quite gotten round to displaying them...
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:45AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month