perl gmail getting script

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

Page 1 of 1

5 Replies - 6500 Views - Last Post: 20 August 2008 - 05:05 AM

#1 x1101  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 26-November 07

perl gmail getting script

Posted 18 August 2008 - 10:12 PM

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:
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

#!/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;



Is This A Good Question/Topic? 0
  • +

Replies To: perl gmail getting script

#2 x1101  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 26-November 07

Re: perl gmail getting script

Posted 19 August 2008 - 08:44 AM

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,

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 August 2008 - 08:45 AM

Was This Post Helpful? 1

#3 KevinADC  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: perl gmail getting script

Posted 19 August 2008 - 09:17 PM

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.
Was This Post Helpful? 1
  • +
  • -

#4 x1101  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 26-November 07

Re: perl gmail getting script

Posted 19 August 2008 - 10:55 PM

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 ()?
Was This Post Helpful? 0
  • +
  • -

#5 KevinADC  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: perl gmail getting script

Posted 19 August 2008 - 11:14 PM

You can't. You could move the \ Q and \E to inside the parenthesis though.
Was This Post Helpful? 0
  • +
  • -

#6 homemade-jam  Icon User is offline

  • Gabe's Nemesis
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,300
  • Joined: 17-March 08

Re: perl gmail getting script

Posted 20 August 2008 - 05:05 AM

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...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1