php 파싱! 간편하면서 강력한 - PHP Simple HTML DOM Parser 정보
PHP php 파싱! 간편하면서 강력한 - PHP Simple HTML DOM Parser관련링크
본문
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>';
// 컨텐츠내에 텍스트들만 가져옵니다.
echo file_get_html('http://www.google.com/')->plaintext;
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;
}
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
3
댓글 15개
사용하기 쉽지만 성능면에서는 어떨지 궁금하네요.
괜춘하네요!!
크롤러 소스네요 ㅋㅋ 좋네요 ㅋㅋ
감사합니다.
좋네요.~~
감사합니다.
감사합니다.
snoopy.class 얼마전에 처음 알고 신기해했는데. 이것도 좋아보이네요^^
오호............
그누보드랑 접목 시킨 예제는 없을까요? 삽질 연속중..ㅠㅠ
해보시면서 궁금하신 부분 여쭤보세요 도움닫는한 답변드릴께요 ㅎㅎ
감사합니다.
샘플 형태로 다 진행을 해봤는데요. 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저장시킬 방법을 찾고있습니다.
샘플 형태로 다 진행을 해봤는데요. 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 파일 직접한번 봐보셔두 됩니다 ㅎㅎ
grep allow_url_fopen /etc/php.ini
입력해보세요.
allow_url_fopen 설정이 on인지 off인지 보일꺼에요.
on이 되어있어야 합니다.
php.ini 파일 직접한번 봐보셔두 됩니다 ㅎㅎ
.htaccess 에
php_flag register_globals on 설정되어있습니다.
ㅠㅠ
php_flag register_globals on 설정되어있습니다.
ㅠㅠ
감사드려요
좋긴 한데..메모리누수 버그가 있었는데..지금은 패치가 되엇나요??
clear, destruct, unset...등 조치해야 되었던거 같은데..
무지...편리하긴 한데..
clear, destruct, unset...등 조치해야 되었던거 같은데..
무지...편리하긴 한데..
죄송한데, 이러한 소스를 결국 어디에 입력해야 게시판에 파싱된 글들이 올라오나요??