如何使用简单的html-dom-php隔离特定的超链接


How to isolate specific hyperlinks using simple html dom php

如何从网站中隔离特定的超链接(使用简单的html-dom-php)。例如,下面的脚本是我只想要带有粗体路径的链接http://www.website.com/发布/。。。

<a class="blue" href="/releases/2012.htm">release of ---</a>
<a class="blue" href="/releases/1/2012.htm">release of ---</a>

以及在中有子域(新闻)的链接

 <a class="blue" href="http://news.website.com/one/1">release of ---</a>

还有没有任何方法可以将特定链接从网站中隔离出来,进入该特定链接并获取其标题和描述

通常情况下,您只需遍历所有链接,检查每个链接是否符合您的条件,如果符合,则从中获取您想要的数据。

foreach($html->find('a') as $link) {
    if(substr($link->href, 0, 10) == "/releases/") {
        // do stuff with a releases link
    }
    // and so on
}

遍历所有可能匹配的链接,然后检查它们的href是否符合您的条件。如果条件对于基本匹配过于高级,则可以使用基本字符串函数或正则表达式进行此检查。