[ Web 관련 ]/php

php 크롤링 (simple_html_dom, Snoopy)

BIZLAB 2021. 7. 22. 18:25

simple_html_dom 사이트에서 simple_html_dom.php 다운로드를 합니다.

다운로드 URL : https://sourceforge.net/projects/simplehtmldom/files/simplehtmldom/ 에서 최신버전 다운로드

온라인 설명서 URL : http://simplehtmldom.sourceforge.net/manual.htm 개발시 참조


simplehtmldom_1_9_1.zip
0.08MB

<?php

header('Content-Type: text/html; charset=UTF-8'); 

//simple_html_dom php 파일을 include함 
include('simple_html_dom.php'); 

//가져올 url 설정
$url = 'https://tv.zum.com/ranking'; 
$html = @file_get_html($url); 

unset($arr_result); 
$arr_result = $html->find('div.tv_wrap>a');   //1위 ~ 3위 랭킹순위 및 프로그램명 가져오기
if(count($arr_result) > 0){                         //위의 이미지에서 a 태그에 포함되는 html dom 객체를 가져옴
    foreach($arr_result as $e){

        //children 속성을 이용해 맨 처음(0)의 태그 가져오기(<span class="rank_num">1</span>값 가져옴)
        echo $e->children(0)->plaintext.':';     //위의 값 중 1 값을 가져옴

        //children 속성을 이용해 맨 두번째(1)의 태그(<div class="tv_info">) 안의 두번째(1)의 태그 가져오기(<p class="program">미스트롯</p>값 가져옴)
        echo $e->children(1)->children(1)->plaintext.'<br/>';     //위의 값 중 미스트롯 값을 가져옴
    } 
} else { 
    echo "<br/>"; 
} 

unset($arr_result); 
$arr_result = $html->find('div.list_wrap>div.list');   //4위 ~ 50위 랭킹순위 및 프로그램명 가져오기
if(count($arr_result) > 0){ 
    foreach($arr_result as $e){ 
        echo $e->children(1)->plaintext.':'; 
        echo $e->children(2)->children(1)->children(0)->plaintext.'<br/>'; 
    } 
} else { 
    echo "<br/>"; 
}


exit;

?>

https://chan2727.tistory.com/entry/PHP-simplehtmldom%EA%B4%80%EB%A0%A8-%EC%9B%B9%ED%8E%98%EC%9D%B4%EC%A7%80-%ED%81%AC%EB%A1%A4%EB%A7%81-%EC%98%88%EC%A0%9C

 

 

https://sourceforge.net/projects/simplehtmldom/postdownload

 

Find out more about PHP Simple HTML DOM Parser | SourceForge.net

Why SourceForge? We have the most robust search and discovery system of any open source repository on the web, and offer an unparalleled experience for end-users looking for software binaries they can download and install with the click of a button. We're

sourceforge.net

 

 

==========================================

 

 

https://infotake.tistory.com/98

 

PHP 외부 사이트 가져 오기, 크롤링 - Snoopy.class

촌놈입니다... 고객분이 GitHub의 MarkDown 페이지를 긁어 오기를 요청 하였는데요... 모듈을 알아보던중 Snoopy.class.php 를 테스트 해보게 되었습니다. 실습환경  - PHP 5.6.9  - 가비아 호스팅  - Snoopy...

infotake.tistory.com

https://sourceforge.net/projects/snoopy/

 

Snoopy

Download Snoopy for free. Snoopy is a PHP class that simulates a web browser. It automates the task of retrieving web page content and posting forms, for example.

sourceforge.net