简体   繁体   中英

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

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.

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'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM