简体   繁体   中英

unable to scrape information from this website using php

I tried to scrape information from this site: http://disclosure.bursamalaysia.com/FileAccess/viewHtml?e=2745298

However, when i try to echo $output, something don't seem right and it redirects to localhost site ( http://localhost/FileAccess/viewHtml?e=2745298 )

my source as below

  function curl_download($Url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $start = strpos($output, '<html>'); $end = strpos($output, '</html>', $start); $length = $end-$start; $output = substr($output, $start, $length); curl_close($ch); echo $output; } 

Use following

    function curl_download($Url){

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    $output = curl_exec($ch);
    $start = strpos($output, '<html>');
    $end = strpos($output, '</html>', $start);

    $length = $end-$start;
    $output = substr($output, $start, $length);
    curl_close($ch);

    echo $output;

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM