gpt4 book ai didi

Perl 通过 DOM 查找 Web 链接

转载 作者:行者123 更新时间:2023-12-04 16:19:43 24 4
gpt4 key购买 nike

我一直在使用 Mechanize::Firefox 来做一些网页抓取,我目前正处于完全 headless 的过程中。我一直在使用这个代码:

my $link = [$firefox->find_link_dom(text_regex => qr/pdf/i)]->[0]->{href} . "\n";

这在查找 .pdf 文件时提供了非常好的结果。无论如何,我可以使用不需要显示浏览器的不同模块找到基于 text_regex 的链接末日吗?

编辑

使用 Mechanize::Firefox,我会从代码中获取一个链接,例如:
<div id="rhc" xpathLocation="noDialog">

<div id="download" class="rhcBox_type1">
<div class="wrap">
<ul>
<li class="download icon"><strong>Download:</strong>
<a href="/article/fetchObjectAttachment.action;jsessionid=CDBD1AACEEB3CF89729EB23808FD1319?uri=info%3Adoi%2F10.1371%2Fjournal.pbio.1001193&amp;representation=PDF" title="Download article PDF">PDF</a> |
<a href="/article/citationList.action;jsessionid=CDBD1AACEEB3CF89729EB23808FD1319?articleURI=info%3Adoi%2F10.1371%2Fjournal.pbio.1001193" title="Download citations">Citation</a> |
<a href="/article/fetchObjectAttachment.action;jsessionid=CDBD1AACEEB3CF89729EB23808FD1319?uri=info%3Adoi%2F10.1371%2Fjournal.pbio.1001193&amp;representation=XML" title="Download Article XML">XML</a>
</li>
<li class="print icon"><a href="#" onclick="window.print();return false;" title="Print Article"><strong>Print article</strong></a></li>
<li class="reprint icon"><a href="https://www.odysseypress.com/onlinehost/reprint_order.php?type=A&page=0&journal=1&doi=10.1371/journal.pbio.1001193&volume=&issue=&title=Evolutionarily Conserved Linkage between Enzyme Fold, Flexibility, and Catalysis&author_name=Arvind%20Ramanathan%2C%20Pratul%20K.%20Agarwal&start_page=1&end_page=17" title="Odyssey Press">EzReprint</a> New &amp; improved!</li>
</ul>
</div>

下载pdf文件。为什么 HTML::Treebase 无法获得此链接的任何想法?

最佳答案

  • CSS3 a[href*="pdf"] :Web::Query , HTML::Query , Mojo::UserAgent
  • XPath //a[contains(@href, "pdf")] :HTML::TreeBuilder::XPath , XML::LibXML
  • 关于Perl 通过 DOM 查找 Web 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10249038/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com