我想获取具有特定文档链接的标题和网址。所以,从下面的代码中,我想获取信息:标题和具有特定 url 下载的http://linkWeb.com .pdf http://link.pdf
这是html页面:
<div class="title-download">
<div id="01divTitle" class="title">
<h3>
<a id="01Title" onmousedown="" href="http://linkWeb.com">Titles</a>
<span id="01LbCitation" class="citation">(<a id="01Citation" href="http://citation.com">Citations</a>)</span></h3>
</div>
<div id="01downloadDiv" class="download">
<a id="01_downloadIcon" title="http://link.pdf" onmousedown="" target=""><img id="ctl01_icon" class="small-icon";" /></a>
</div>
这是代码,但它返回空白结果:
<?php
include 'simple_html_dom.php';
set_time_limit(0);
$url ='http://example.com';
$html = file_get_html($url) or die ('invalid url');
foreach($html->find('span[class=citation]') as $link){
foreach($link->parent()->parent()->find('.download a') as $link2){ //I confused with the code in this line
if(strtolower(substr($link2->title, strrpos($link2->title, '.'))) === '.pdf') {
$link = $link->prev_sibling();
echo $link->plaintext.'<br>';
echo $link->href.'<br>';
echo $link2->title.'<br>';
}
}
}
?>