Posted By

Tamedo on 11/23/07


Tagged

curl scrape


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
wirenaught


Scrape with curl


 / Published in: PHP
 

  1. <?php
  2.  
  3. $url="http://test.com/";
  4.  
  5. $ch = curl_init();
  6. $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
  7. curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
  8. curl_setopt($ch, CURLOPT_URL, $url);
  9. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  10. $data = curl_exec ($ch);
  11. curl_close ($ch);
  12.  
  13. $regex = '/<p class=\"title\"><a href=\"\/watch\/([^`]*?)<\/p>/';;
  14. preg_match_all($regex,$data,$match);
  15.  
  16. for ($i=0; $i< count($match[0]); $i++) {
  17. echo "".$match[1][$i]."]";
  18. }
  19.  
  20. ?>

Report this snippet  

You need to login to post a comment.