【发布时间】:2012-09-20 20:27:50
【问题描述】:
html 页面:
<div class="title-download">
<div id="ctl " class="title">
<h3>
<a id="ct2" href="http://url1.com">title</a>
<span id="ct3" class="citation">(<a id="ct4 " href=" ">Citations</a>)</span></h3>
</div>
<div id="ct4" class="download">
<a id="ct5 " title=" " href="http://url.pdf" img id="ct6" class="small-icon" src=" " /></a>
</div>
</div>
<div class="content">
<a class="author " href="author.com">author</a><span class="span-break" >, </span><a class="author2.com " href="http://author2.com">author2</a>
</div>
我想得到http://url1.com、title、http://url.pdf、author.com 和author,如果只有类下载有 pdf 网址。
这是代码:
foreach($html->find('span[class=citation]') as $link1){
foreach($link1->parent()->parent()->parent()->find('.download a') as $link2){
foreach ($link1->parent()->find('div[class=content] a') as $a ){
if(strtolower(substr($link2->title, strrpos($link2->href, '.'))) === '.pdf') {
$link1 = $link1->prev_sibling();
$a = $link1->next_sibling();
$title = strip_tags($link1->plaintext);
$linkWeb = strip_tags($link1->href);
$author= strip_tags($a->plaintext);
$linkAuthor= strip_tags($a->href);
$pdfLink = strip_tags($link2->title);
}
}
}
}
我得到了空白结果,请你帮我,请告诉我错误。在此先感谢:)
【问题讨论】:
-
@WebnetMobile.com 调用
$html = file_get_html('http://www.google.com/');simplehtmldom.sourceforge.net的结果 -
所以更新你的问题。
-
文件是否填充了不同的 div 类 title-download?
-
@DarianLewin 是的,这是不同的 div 类标题下载
-
@WebnetMobile.com 这不是我的问题
标签: php html parsing dom simple-html-dom