【问题标题】:find link in pdf extension在 pdf 扩展名中查找链接
【发布时间】:2012-02-08 04:31:09
【问题描述】:

我需要获取带有 pdf 扩展名的链接。我的代码是:

<?php

set_time_limit (0);
curl_setopt($ch, CURLOPT_URL,"http://example.com");
curl_setopt($ch, CURLOPT_TIMEOUT, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);

preg_match_all( '/<a href="(http:\/\/www.[^0-9].+?)"/', $result, $output, PREG_SET_ORDER); // read all links

foreach($output as $item  ){ 
    $n=strlen($item);
    $m=$n-3;
    $buffer_n=$item;
    $buffer_m="";
    $buffer_m=$buffer_n[$m].$buffer_n[$m+1].$buffer_n[$m+2];
    $ekstension = 'pdf';
        if ($buffer_m == $ekstension) {
           print_r($item);
           echo '<br>';
         }
}

?>

代码给了我空白的结果,我的代码有什么问题?非常感谢:)

【问题讨论】:

    标签: php web-crawler


    【解决方案1】:

    使用简单的html dom解决,代码是:

    <?php
    
    set_time_limit(0);
    include 'simple_html_dom.php';
    $url = 'example';
    $html = file_get_html($url) or die ('invalid url');
    
    foreach($html->find('a') as $e) {
        $link= $e->href;
        if (preg_match('/\.pdf$/i', $link)) {
        }
    }
    
    print_r($result);
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多