perl - 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
&nav_mode=r&std_nav_id=4&pk_mode=in_view&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
" ‐ 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 "
现在我不知道如何按照这个链接来检索整个消息。每次调用页面时,链接的数量和内容都会有所不同。
解决方案
对不起,我自己找到的,它是
# 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'));
推荐阅读
- node.js - 两个渲染的空 PDF 不相同
- java - 如何从 api graphQL 获取数据?
- c++ - 整数表达式的 C++ 常量折叠的预期行为是什么?
- excel - Excel 的 Workbook_Open() 事件实际上是如何工作的?
- html - 是否可以在 iframe 中使用 Ruffle?
- javascript - 将折叠/展开 onClick 嵌套子菜单添加到现有菜单树
- python - python子进程命令谷歌云平台中的权限被拒绝
- r - 如何在 R 中的 geom 中使用下标或任何数学注释?
- python - 如何格式化字典(最初来自数据框)以供操作使用?
- reporting-services - 使用从 SQL Server 到 Sybase 的 openquery 将 SSRS 参数注入