메뉴 건너뛰기

프로그램언어

조회 수 898 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

http://simplehtmldom.sourceforge.net/

 

https://github.com/samacs/simple_html_dom

 

다운로드 링크 : http://sourceforge.net/projects/simplehtmldom/files/latest/download?source=files

 

해당 홈에 나와있는 예제입니다.

 

간단한 주석을 붙입니다.

 

//html 을 가져오고

$html = file_get_html('http://www.google.com/');            



// 모든 이미지태그를 찾아냅니다.

foreach($html->find('img') as $element) 

       echo $element->src . '<br>';                                  



// 모든 a태그를 찾아내어 href속성을 뿌려줍니다.

foreach($html->find('a') as $element)                             

       echo $element->href . '<br>';



// 컨텐츠내에 텍스트들만 가져옵니다.

echo file_get_html('http://www.google.com/')->plaintext; 



// css jquery 많이 만져보셨다면 선택자는 거의 동일합니다.

//몇번째 a태그 같은 경우도 가져올수 있구요

foreach($html->find('div.article') as $article) {

    $item['title']     = $article->find('div.title', 0)->plaintext;

    $item['intro']    = $article->find('div.intro', 0)->plaintext;

    $item['details'] = $article->find('div.details', 0)->plaintext;

    $articles[] = $item;

}



//가져오기전 해당 태그내의 텍스트도 이렇게 간단히 변경가능합니다.

$html->find('div[id=hello]', 0)->innertext = 'foo';



예제

<?php

include_once('simplehtmldom_1_5/simple_html_dom.php');

// 네이버 html을 가져온다

$html = file_get_html('http://www.naver.com/');



// 모든 이미지태그를 찾고

foreach($html->find('img') as $element) {

       echo $element->src . '<br>';

}       

 

// 모든 a태그를 찾아내어 href속성을 뿌려줍니다.

foreach($html->find('a') as $element) {                            

       echo $element->href . '<br>';

}    

?>

 


List of Articles
번호 제목 날짜 조회 수
340 PHP 버전 숨기기 ( php version hide ) 2024.02.06 897
339 php 암호화 복호화 , 간단한 암호화 2023.01.12 1044
338 PHP 디렉토리안에 파일 리스트 가져오기 2023.01.12 769
337 그누보드 https 보안서버 연결시 오류 2023.01.12 849
336 php 두날짜 사이의 모든날짜 배열 만들기 2023.01.12 728
335 php 간단 심플한 달력만들기 file 2023.01.12 804
334 간단한 캡차파일 만들기 captcha file 2023.01.12 940
333 PHP str_replace php 문자열치환 2023.01.12 755
332 curl을 이용하여 post, get 방식 으로 데이터 전송하기 2023.01.12 1146
331 php 이미지 리사이징 image resizing 2023.01.12 843
330 PHP ZIP 압축파일 만들기 file 2023.01.12 883
329 ereg(), eregi(), ereg_replace(), eregi_replace(), split() 대체 2023.01.12 812
328 PHP 브라우저 알아내기 2023.01.12 863
» PHP SimpleHtmlDom Parser로 HTML 파싱하기 2023.01.12 898
326 웹페이지 파싱 2023.01.12 883
325 폴더 용량 체크 2023.01.12 918
324 코드 생성 하기 2023.01.12 719
323 PHP웹 보안 취약점 TOP5(웹해킹) 2023.01.12 909
322 PHP 하위 디렉토리 포함 디렉토리 리스트 출력 2023.01.12 1144
321 PHP 파일 업로드 FORM 처리 2023.01.12 1079
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved