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 업데이 트를 통해 RSS | 이메일 Get updates via feedburner Get updates via twitter
Home / Coding / PHP / PHP: How to download a webpa… / 코딩 / PHP는 / PHP는 : 어떻게 webpa 다운로드 ...

PHP: How to download a webpage (aka web scrapping) with PHP PHP는 : 어떻게 PHP로 웹페이지 (일명 웹 폐기) 다운로드

Posted on 03. 03 게시됨. Oct, 2009 by Dragos in Coding , PHP 10월, 2009 코딩, PHP로의 드라 고스에 의해

There are many ways of downloading web pages, or web content. 거기에 웹 페이지 또는 웹 콘텐츠를 다운로드하는 방법에는 여러가지가있습니다. Personally I like to use cURL for my web scrapping needs, but sometimes I also use fsockopen and file_get_contents . 개인적으로 난 cURL을 내 웹 폐기 요구에 사용할 수도 있지만 가끔은 fsockopen과 file_get_contents도 사용할 수있습니다.

Here are 3 different functions that will allow you to download web content. 여기에서 당신의 웹 콘텐츠를 다운로드하실 수에 3을 올리는 기능이있습니다.

cURL : cURL을 사용 :

 function getData($url) { 함수 GetData ($ URL)를 ( 
     if($url!='localhost' && $url!='http://localhost') { ($ 만약 URL이! = '& & $ localhost를 URL에! ='http://localhost를 ') ( 
         $ch=curl_init(); $ 채널 = curl_init (); 
         curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ 채널, CURLOPT_URL, $ URL)를; 
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt ($ 채널, 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 ($ 채널, CURLOPT_USERAGENT, "Mozilla/6.0 (Windows 용; U;는 Windows NT 5.1; 엉 - 한미; RV가 : 1.9.0.1) Gecko/2008070208 Firefox/3.0.3"); 
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION,3); curl_setopt ($ 채널, CURLOPT_FOLLOWLOCATION, 3); 
         $result['data']=curl_exec($ch); $ 결과 [ '데이터'] = curl_exec ($ 채널); 
         $result['error']=curl_error($ch); $ 결과 [ '오류'] = curl_error ($ 채널); 
         curl_close($ch); curl_close ($ 채널); 
         return $result; 결과는 $ 반환; 
     } ) 
     else return $result['error']='err'; 다른 결과를 반환 $ [ '오류'] = '잘못'; 
 } ) 

fsockopen 은 fsockopen

 function getData($url) { 함수 GetData ($ URL)를 ( 
     $arr=parse_url($url); $ arr = parse_url ($ URL)를; 
     $fp = fsockopen($arr['host'], 80, $errno, $errstr, 30); $ FP가 =은 fsockopen ($ arr [ '호스트'], 80, $ errno, $ errstr, 30); 
     if(!$fp) { (! $ FP가) 만약 ( 
         return false; 돌아 거짓; 
     }else { 다른) ( 
     // send headers / / 헤더를 보내려면 
         $out = "GET ".fsockopen($arr['host'], 80, $errno, $errstr, 30)." HTTP/1.1\r\n"; $ 아웃 = "".은 fsockopen ($ arr GET [ '호스트'], 80, $ errno, $ errstr, 30). "는 HTTP/1.1에 \ r \ n"; 
         $out .= "Host: ".str_replace('http://'.$arr['host'],'',$url)."\r\n"; $ .= "호스트 아웃 :". str_replace ( 'http://'를. $ arr [ '호스트 '],'',$ URL을). "에 \ r \ n"; 
         $out .= "User-Agent: FSOCKOPEN\r\n"; $ .=는 "User - Agent로 아웃 :은 fsockopen에 \ r \ n"; 
         $out .= "Connection: Close\r\n\r\n"; $ .= "연결 아웃 : 주변에 \ r \ n \ r에 \ n"; 
         fwrite($fp, $out); fwrite ($ FP가, $ 아웃); 
         while(!feof($fp)) { (! feof ($ FP가)) 동안 ( 
             $contents .= fgets($fp, 4096); $ 콘텐츠 .= fgets ($ FP가, 4096); 
         }; ); 
         fclose($fp); fclose ($ FP가); 
         return $contents; $ 콘텐츠를 반환; 
     } ) 
 } ) 

file_get_contents file_get_contents

 function getData($url) { 함수 GetData ($ URL)를 ( 
 return file_get_contents($url); 반환 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. 다음, cURL을 마찬가지로 웹 콘텐츠를 다운로드하는 가장 쉬운 방법을 참조하십시오 file_get_contents 함수를 사용하여,하지만 만약 당신이, 특히 만일 당신이 헤더와 함께 작업하는 더 많은 옵션이 필요합니다 당신이 가야하는 가장 좋은 방법입니다.

Translate this post 번역이 게시물에


No related posts. 관련 게시물 없음.

  • saya kemarin juga ngerjain web yang grabb data dari website lain... Saya kemarin juga ngerjain 웹 grabb 데이터 양 웹사이트에 영하 dari ...

    sayang ga sempat baca artikel ini, jadi nya pake file_get_contents().. Sayang 187-20 sempat Baca artikel ini를, jadi 냐 호다이로의 file_get_contents () .. di potong2 pake preg_replace(), buat ngambil data yang di butuh kan... 디 potong2 호다이로의 preg_replace (), 뷔아 ngambil 데이터를 디 butuh 토관 양 ...


    btw salam kenal... btw 살람 kenal ...
blog comments powered by Disqus 블로그 덧글 Disqus에 의해 제공