从Web上删除信息


Scraping information from the Web

如何获取信息(http://linkWeb.com,标题,以及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>
</div>

我试过了,但它只返回标题。我以前不知道simple_tml_dom。请帮帮我。谢谢:)

<?php
include 'simple_html_dom.php';
set_time_limit(0);
$url  ='http://libra.msra.cn/Search?query=data%20mining&s=0';
$html = file_get_html($url) or die ('invalid url');
foreach($html->find('div[class=title-download]') as $webLink){
    echo $webLink->plaintext.'<br>';
    echo $webLink->href.'<br>';
}
foreach($html->find('div[class=download]') as $Link2){
    echo $webLink2->href.'<br>';    
}
?>

我认为您需要在div中选择一个具有类标题下载的元素。至少文档中说它使用了像jQuery这样的选择器(http://simplehtmldom.sourceforge.net/)

这样试试:

$html = file_get_html($url) or die ('invalid url');
foreach($html->find('.title a') as $webLink){
    echo $webLink->plaintext.'<br>';
    echo $webLink->href.'<br>';
}
foreach($html->find('.download a') as $link){
    echo $link->title.'<br>';    
}

使用LibXML分析HTML,并使用XPaths指定所需的元素或元素属性。

使用以下代码废弃标题和URL:

foreach($html->find('span[class=citation]') as $link){
  $link = $link->prev_sibling();
  echo $link->plaintext.'<br>';
  echo $link->href.'<br>';
}

并使用@zigomir给出的答案在类下载中废弃url:)

foreach($html->find('.download a') as $link){
   echo $link->title.'<br>';    
}