【发布时间】:2013-08-24 19:23:36
【问题描述】:
尝试使用 iMacros for Firefox 插件提取链接 url。
以下输入 html代码在要抓取的网站上:链接url和描述
<div class="subcl">
<a href="http://www.url.com/someurl.html" target="_blank">description</a>
</div>
来自 iMacros 的所需 输出:只需链接 url
http://www.url.com/someurl.html
由于网站上有更多链接,因此 class="subcl" 应包含在代码中。也许有一种方法可以实现嵌套结构?如果可能的话,我更喜欢非 Javascript 代码,因为我自己不会在其中编写代码。
以下宏代码不起作用
VERSION BUILD=8300326 RECORDER=FX
TAB T=1
'Open the website
URL GOTO=http://www.url.com/pagetobescraped.html
'Extract the link url on the page
TAG POS=1 TYPE=DIV ATTR=CLASS:subcl* EXTRACT=HREF
宏返回#EANF#(到达文件末尾但没有匹配)。当我将 EXTRACT=HREF 替换为 EXTRACT=TXT 时,它会返回 "description" 但我需要 URL。
编辑
澄清 symbiotech 的答案:输入的 html 代码之前是元素 <h1> 以及 <p>。总而言之,它看起来像这样......
<h1>Title of the page</h1><p class="intro"></p>
<div class="subcl">
<a href="http://www.url.com/someurl.html" target="_blank">description</a>
</div>
【问题讨论】:
标签: firefox-addon web-scraping imacros