首页 > 解决方案 > perl WWW::Mechanize 跟踪某个表行中的链接

问题描述

我正在尝试编写一个脚本,将内部办公室邮件传输到我的普通邮件帐户。我看到识别未读邮件的唯一方法是,它们<tr>具有特殊样式(“粗体预览”)。我能够将<tr>-element 存储在 HTML 元素中,dump() 给了我:

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

现在我不知道如何按照这个链接来检索整个消息。每次调用页面时,链接的数量和内容都会有所不同。

标签: perlwww-mechanize

解决方案


对不起,我自己找到的,它是

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

推荐阅读