php 파싱! 간편하면서 강력한 - PHP Simple HTML DOM Parser
링크
http://simplehtmldom.sourceforge.net/ (1225) http://sourceforge.net/projects/simplehtmldom/files/latest/download?source=files (2590)
http://simplehtmldom.sourceforge.net/
다운로드 링크 : 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>';
$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>';
// 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;
}
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';
현재 홈에는 예제가 별로 안나와있는데 파일받아보시면
풍부한 예제가 많습니다.
강력추천드립니다 ㅋㅎ
|
댓글을 작성하시려면 로그인이 필요합니다.
로그인
프로그램
태그 필터 (최대 3개)
전체
개발자
소스
기타
mysql
팁자료실
javascript
php
linux
flash
정규표현식
jquery
node.js
mobile
웹서버
os
프로그램
강좌
썸네일
이미지관련
도로명주소
그누보드5
기획자
견적서
계약서
기획서
마케팅
제안서
seo
통계
서식
통계자료
퍼블리셔
html
css
반응형
웹접근성
퍼블리싱
표준화
반응형웹
홈페이지기초
부트스트랩
angularjs
포럼
스크린리더
센스리더
개발자톡
개발자팁
퍼블리셔톡
퍼블리셔팁
기획자톡
기획자팁
프로그램강좌
퍼블리싱강좌
댓글 14개
감사합니다.
샘플 형태로 다 진행을 해봤는데요. URL 구글로 샘플된거 해보면 계속
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home1/**********/parser/simple_html_dom.php on line 75
이렇게 오류가 생기네요.
ㅠㅠ
구현하고 싶은것은 그누보드에 url 입력창에 입력하면 특정 게시물의 일부 또는 전체를 가져올까합니다. 블로그 같은경우 최신 RSS 50개만 적용되어서요. 50개이전글을 가져와서 DB저장시킬 방법을 찾고있습니다.
grep allow_url_fopen /etc/php.ini
입력해보세요.
allow_url_fopen 설정이 on인지 off인지 보일꺼에요.
on이 되어있어야 합니다.
php.ini 파일 직접한번 봐보셔두 됩니다 ㅎㅎ
php_flag register_globals on 설정되어있습니다.
ㅠㅠ
clear, destruct, unset...등 조치해야 되었던거 같은데..
무지...편리하긴 한데..