This is a translated page. The original can be found here: http://iwebdevel.com/2009/10/03/php-how-to-download-a-webpage-aka-web-scrapping-with-php-fsockopen-file_get_contents-curl-function-download-web-page/
UPDATES VIA RSS | Email GÜNCELLEME VIA RSS | E-posta Get updates via feedburner Get updates via twitter
Home / Coding / PHP / PHP: How to download a webpa… Ana Sayfa / Kodlama / PHP / PHP: Nasıl webpa indirmek için ...

PHP: How to download a webpage (aka web scrapping) with PHP PHP: Nasıl bir web sayfası PHP ile (aka web hurdaya) indirmek için

Posted on 03. 03 olarak gönderildi. Oct, 2009 by Dragos in Coding , PHP Eki, 2009 Kodlama, PHP ve Dragos tarafından

There are many ways of downloading web pages, or web content. Orada web sayfalarını veya web içerik indirme birçok yolu vardır. Personally I like to use cURL for my web scrapping needs, but sometimes I also use fsockopen and file_get_contents . Şahsen ben cURL web hurdaya ihtiyaçları için kullanılacak, ancak bazen de fsockopen file_get_contents ve kullanın.

Here are 3 different functions that will allow you to download web content. İşte size ücretsiz web içeriği sağlayacak 3 farklı işlevleri vardır.

cURL : cURL:

 function getData($url) { fonksiyonu getData ($ url) (
    if($url!='localhost' && $url!='http://localhost') { if ($ url = '' & & $ localhost url = 'http://localhost') (
        $ch=curl_init(); $ ch = curl_init ();
        curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ ch, CURLOPT_URL, $ url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/6.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.3"); curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/6.0 (compatible; Windows NT 5.1; en-US; rv: 1.9.0.1) Gecko/2008070208 Firefox/3.0.3");
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION,3); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 3);
        $result['data']=curl_exec($ch); $ result [ 'veri'] = curl_exec ($ ch);
        $result['error']=curl_error($ch); $ result [ 'hata'] = curl_error ($ ch);
        curl_close($ch); curl_close ($ ch);
        return $result; return $ result;
    } )
    else return $result['error']='err'; else return $ result [ 'hata'] = 'err';
} ) 

fsockopen fsockopen

function getData($url) { $arr=parse_url($url); $fp = fsockopen($arr['host'], 80, $errno, $errstr, 30); if(!$fp) { return false; }else { // send headers $out = "GET ".fsockopen($arr['host'], 80, $errno, $errstr, 30)." HTTP/1.1\r\n"; $out .= "Host: ".str_replace('http://'.$arr['host'],'',$url)."\r\n"; $out .= "User-Agent: FSOCKOPEN\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while(!feof($fp)) { $contents .= fgets($fp, 4096); }; fclose($fp); return $contents; } } fonksiyonu getData ($ url) ($ arr = parse_url ($ url); $ fp = fsockopen ($ arr [ 'host'], 80, $ errno, $ errstr, 30) if ($ fp) (return false; out = "GET) else (/ /" başlıklarını $ gönderebilirsiniz. fsockopen ($ arr [ 'host'], 80, $ errno, $ errstr, 30). "HTTP/1.1 \ r \ n"; $ .= out " host: ". str_replace ( 'http://'. $ arr [ 'host'],'',$ URL)." \ r \ n "; $ out .=" User-Agent: fsockopen \ r \ n " $ out .= "Connection: Close \ r \ n \ r \ n"; ($ fp, $ out) while (! feof ($ fp)) ($ contents .= fgets ($ fp, 4096) fwrite; ); fp) ($ fclose $ içeriği; return)) 

file_get_contents file_get_contents

 function getData($url) { fonksiyonu getData ($ url) (
return file_get_contents($url); return file_get_contents ($ url);
} ) 

As you see the easiest way of downloading web content is by using the file_get_contents function, but if you need more options, especially if you are working with the headers, then cURL is the best way to go for you. , Sonra cURL gibi web içerik indirme ve kolay yolu görmek file_get_contents fonksiyonunu kullanarak, ancak eğer özellikle başlıklarını çalışırken daha fazla seçenek ihtiyacınız gitmek için en iyi yoldur.

Translate this post Translate bu yazı


Related posts: Ilgili posta:

  1. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: başka bir işlev (geriçağırımları) bir parametre olarak işlev gönder

  • saya kemarin juga ngerjain web yang grabb data dari website lain... saya kemarin juga ngerjain web sitesi grabb veri yang lain dari ...

    sayang ga sempat baca artikel ini, jadi nya pake file_get_contents().. sayang ga sempat baca artikel ini, jadi nya Pake file_get_contents () .. di potong2 pake preg_replace(), buat ngambil data yang di butuh kan... di potong2 Pake preg_replace (), buat ngambil veri di butuh kan yang ...


    btw salam kenal... btw salam kenal ...
blog comments powered by Disqus Blog Yorumlar Disqus tarafından desteklenmektedir