0

Here's my code:

<?php
    set_time_limit(0);
    $agent = 'User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008100922 Ubuntu/8.04 (hardy) Firefox/3.0.3';
    $url = "XXXXXXXX";

    $ch = curl_init ($url);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $data = curl_exec ($ch);
    curl_close($ch);

    $regex = '/<tr>(.*?)<\/tr>/s';
    preg_match_all($regex,$data,$match);
    $tr = $match[0][0];
    var_dump($tr);

if(curl_errno($ch)){ // check for execution errors
    echo 'Scraper error: ' . curl_error($ch);
    exit;
}
?>

Here's what's outputted:

array (size=0)
  empty

Here's what's being scraped:

<table>
    <tr><td>Title</td><td>Message</td></tr>
    <tr><td>Title</td><td>Message</td></tr>
</table>

Any ideas for troubleshooting to make sure the page is being loaded correctly or anything obvious that I'm missing?

Here's the error I am receiving:

 Warning: curl_errno(): 2 is not a valid cURL handle resource in 

I suppose it looks like it's due to a lack of SSL. Thanks for the assistance everybody.

Eric
  • 565
  • 1
  • 8
  • 25
  • you are obviously missing that this is [easier with an HTML parser](http://stackoverflow.com/questions/3577641/best-methods-to-parse-html/3577662#3577662) – Gordon Feb 27 '13 at 18:40
  • Now that I have my own server these are actually valid options, I originally started this on a shared host where many of the options you listed were not available. Regardless thank you for your input. – Eric Feb 27 '13 at 18:46
  • Write like this `echo '
    ' . print_r($data, 1) . '
    ';` and show what will be outputting.
    – Winston Feb 27 '13 at 18:58
  • Hi Winston, I appreciate the assistance. I add curl error outputting and I believe I have located the issue which is due to a lack of SSL. The link was an https:// which I suppose may have helped give a clue as to the problem if I had included it but unfortunately I had removed it from the post. – Eric Feb 27 '13 at 19:26

0 Answers0