PHP & Others

[PHP] Snoopy Class, 무엇이든 읽어오는 강력한 소켓 클래스

페이지 정보

본문

스누피 클래스(Snoopy Class) 다운로드
http://sourceforge.net/projects/snoopy/

스누피 클래스의(Snoopy Class) 특징 입니다.

* easily fetch the contents of a web page
* easily fetch the text from a web page (strip html tags)
* easily fetch the the links from a web page
* supports proxy hosts
* supports basic user/pass authentication
* supports setting user_agent, referer, cookies and header content
* supports browser redirects, and controlled depth of redirects
* expands fetched links to fully qualified URLs (default)
* easily submit form data and retrieve the results
* supports following html frames (added v0.92)
* supports passing cookies on redirects (added v0.92)

스누피 클래스의(Snoopy Class) 주요 함수 입니다.

CLASS METHODS:

fetch($URI)
-----------
This is the method used for fetching the contents of a web page.
$URI is the fully qualified URL of the page to fetch.
The results of the fetch are stored in $this->results.
If you are fetching frames, then $this->results
contains each frame fetched in an array.
fetchtext($URI)
---------------
This behaves exactly like fetch() except that it only returns
the text from the page, stripping out html tags and other
irrelevant data.

fetchform($URI)
---------------
This behaves exactly like fetch() except that it only returns
the form elements from the page, stripping out html tags and other
irrelevant data.

fetchlinks($URI)
----------------
This behaves exactly like fetch() except that it only returns
the links from the page. By default, relative links are
converted to their fully qualified URL form.

submit($URI,$formvars)
----------------------
This submits a form to the specified $URI. $formvars is an
array of the form variables to pass.
submittext($URI,$formvars)
--------------------------
This behaves exactly like submit() except that it only returns
the text from the page, stripping out html tags and other
irrelevant data.

submitlinks($URI)
----------------
This behaves exactly like submit() except that it only returns
the links from the page. By default, relative links are
converted to their fully qualified URL form.


외부에서 소켓으로 파일을 열지 못하는 경우 스누피 클래스를 사용하여 읽어올 수 있습니다.

예를들어 RSS 피드에서 이미지를 읽어서 썸네일로 만들어야 하는데 외부에서 이미지를 읽지 못하도록 서버에서 막아둔 경우 이런 우회적인 방법을 통해 썸네일을 만들 수 있습니다.

넘즈허브등의 메타블로그에서 스누피 클래스를 사용하여 티스토리 블로그의 이미지를 읽어 정상적으로 썸네일을 보여주지만 GR Paper의 경우 이미지를 읽지못해 썸네일을 보여주지 못합니다.

GR Paper, 대부분의 이미지가 썸네일을 만들지 못했다 ㅡㅡ

GR Paper, 대부분의 이미지가 썸네일을 만들지 못했다 ㅡㅡ


위와같이 외부에서 이미지를 읽지 못한 경우 썸네일 대신 403 - Access Denied(접근 거부)나 Error opening등의 에러를 볼 수 있습니다.

외부에서 이미지를 읽어 썸네일을 만드는 경우 외에도 이 스누피 클래스를 이용하여 GPS 로그 파일도 외부에서 읽어들일 수 있습니다.
- 저의 경우 이게 목적이죠 ^^

그동안은 포털에서 제공하는 서비스형의 블로그중 이글루스에서만 첨부 파일을 외부에서 소켓으로 읽을 수 있었지만 이 스누피 클래스를 이용하면 티스토리나 텍스트큐브 닷컴에 올린 로그 파일도 읽을 수 있습니다.

사용법은 정말 간단 합니다.

<?php
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->fetch("읽어들일 주소");
print $snoopy->results;
?>

위와 같이 몇줄만 추가해주면 됩니다.

저의 용도로는 fetch 함수 하나면 손쉽게 해결이 되니 정말 편합니다 ^^

티스토리에서 2% 부족했던게 스누피 클래스를 사용하면 해결이 되니 이제 슬슬 GPS 로그 파일 정리해서 블로그에 올려도 되겠습니다~!


# 스누피 클래스의 사용법에 대해선 질문하지 마세요~!
위의 사용법에 적은것만(길어봐야 사용시간 5분?) 해봤습니다.


이 글은 '상오기 : 자전거 여행과 GPS~!' 의 "상오기™ (sangogi@gmai.com)" 이 작성 하였습니다.
"상업적 이용 금지, 원본 출처(링크 포함) 및 저작자 표시, 내용 변경 금지"의 조건으로 자유롭게 사용하실 수 있으며 저작권에 대한 자세한 내용은 "저작권 안내를 참고 하시기 바랍니다.

관련자료

등록된 댓글이 없습니다.
Today's proverb
내가 존재하기에 내 안의 이 세상은 존재한다.