perl WWW::Mechanize follow link in a certain table row

65 Views Asked by At

I'm trying to write a script, that transfers internal office mails to my normal mail-account. The only way I see to identify unread mails is, that they are in a <tr> with a special style ('bold preview'). I'm able to store the <tr>-element in a HTML-Element, a dump() gives me:

<tr class="bold preview"> @0.1.0.2.0.0.0.0.2.0.4.3.1.3
<td class="collapsing" style="padding-top: .4em; padding-bottom: .4em;" 
valign="top"> @0.1.0.2.0.0.0.0.2.0.4.3.1.3.0
<input class="pk-check-select" name="pk_in_del[145930]" 
onchange="checked_pk(this)" type="checkbox" value="1" /> 
@0.1.0.2.0.0.0.0.2.0.4.3.1.3.0.0
<td style="padding-top: .4em; padding-bottom: .4em;" valign="top"> 
@0.1.0.2.0.0.0.0.2.0.4.3.1.3.1
" M. S. "
<td style="padding-top: .4em; padding-bottom: .4em;" valign="top"> 
@0.1.0.2.0.0.0.0.2.0.4.3.1.3.2
<a class="pk-subject-line"  href="../index.php&
csrf=1ff5569125fc9b41427d5816e5ba52912738e40a12df58f053f3c9886c7989dc
&amp;nav_mode=r&amp;std_nav_id=4&amp;pk_mode=in_view&amp;PK_ID=145930" 
title="Messaging-Dienste "> @0.1.0.2.0.0.0.0.2.0.4.3.1.3.2.0
" Messaging-Dienste "
<span class="preview"> @0.1.0.2.0.0.0.0.2.0.4.3.1.3.2.0.1
" &dash;  Werte Kolleginnen und Kollegen, hier eine Zusammenfassun..."
" "
<td class="right aligned" style="padding-top: .4em; padding-bottom: .4em;" 
valign="top"> @0.1.0.2.0.0.0.0.2.0.4.3.1.3.3
" 10.12.2018 - 15:52 " 

now I have no idea how to follow this single link to retrieve the whole message. The number and the content of the link varies everytime, the page is called.

1

There are 1 best solutions below

0
Franz Müller On

Sorry, I found it myself, it's

# get all the table rows
my @list2 = $mech->look_down('_tag' => 'tr',
                            'class' => 'bold preview');
# only the first is of interest
if(!defined $list2[0]){exit 0;}
# get all the links, only the first matters
my @linklist= $list2[0]->look_down(_tag => 'a');
# follow the link
$mech->get($linklist[0]->attr('href'));