왜 그동안 삽질을 하고 있었던걸까? snoopy 1.2.3 버전 구문오류 해결법
스누피 README 파일
호스팅에서 사이트 긁어오기 (부제:로또 번호 긁어오기)
위에 글에서도 적었지만, 일반 호스팅에서는 외부에 있는 파일을 file,fopen으로 가져오는것을 막아 놨다. 그래서 꽁수로 python을 쓰면 된다고 흥분하며 말했다.
그.런.데. 당연히 안될거라 생각했던 fsocket은 된다. -_-;
난 왜 저걸 하고싶어서 파이썬 책을 두권이나 샀던걸까 ..
/(
//\\
// )_.-"""-._,-""-.
\\ ^,'_\ /_\ )
`./ /O\| |/O\\ /
\ \_/| |\_/ \_/
\ .' _ `. /
.-. ( .:(_):. ) ,-.
( `._`._.-._,'_,' )
) (
( .-------------. ) hjw
`-' `-'
마지막 버전은 http://snoopy.sourceforge.net/ 에서 구할수 있다.
하지만 .. 지금 현재 마지막 버전인 snoopy 1.2.3 는 구문 오류가 난다.
722번째 줄에서 구문오류가 날것이다.
722번째 줄을 보면 아래와 같다
"?,
"?,
"?,
"?,
"?,
"?,
"?,
이걸 아래와 같이 바꿔주면 된다.
"?",
"?",
"?",
"?",
"?",
"?",
"?",
아마도 어떤 특수 문자들 같은데 한글 윈도우에서는 보이지 않거나 깨져버린것같다.
그래서 ? 로 바뀌어버리면서 구문오류가 난것같다. (이유는 정확하지 않음)
일단 다운 받아서 원하는 디렉토리에 스누피를 넣어두시고 아래와 같이 사용하면 된다
include "Snoopy.class.php";
아 놀라워라.. 너무 쉽다.
$snoopy = new Snoopy;
$snoopy->fetchtext("http://www.php.net/");
print $snoopy->results;
이런것도 가능하다.
$submit_url = "http://lnk.ispi.net/texis/script-xs/msearch/netsearch.html";
저 주소로 쿼리를 보내서 결과값을 값는것이다.
$submit_vars["q"] = "amiga";
$submit_vars["submit"] = "Search!";
$submit_vars["searchhost"] = "Altavista";
$snoopy->submit($submit_url,$submit_vars);
print $snoopy->results;
이외에도 여러가지 기능들이 많다.
자세한건 README 파일 참조
NAME:
Snoopy - the PHP net client v1.2.2
SYNOPSIS:
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->fetchtext("http://www.php.net/");
print $snoopy->results;
$snoopy->fetchlinks("http://www.phpbuilder.com/");
print $snoopy->results;
$submit_url = "http://lnk.ispi.net/texis/script-xs/msearch/netsearch.html";
$submit_vars["q"] = "amiga";
$submit_vars["submit"] = "Search!";
$submit_vars["searchhost"] = "Altavista";
$snoopy->submit($submit_url,$submit_vars);
print $snoopy->results;
$snoopy->maxframes=5;
$snoopy->fetch("http://www.ispi.net/");
echo "<PRE>\n";
echo htmlentities($snoopy->results[0]);
echo htmlentities($snoopy->results[1]);
echo htmlentities($snoopy->results[2]);
echo "</PRE>\n";
$snoopy->fetchform("http://www.altavista.com");
print $snoopy->results;
DESCRIPT-xION:
What is Snoopy?
Snoopy is a PHP class that simulates a web browser. It automates the
task of retrieving web page content and posting forms, for example.
Some of Snoopy's features:
* 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)
REQUIREMENTS:
Snoopy requires PHP with PCRE (Perl Compatible Regular Expressions),
which should be PHP 3.0.9 and up. For read timeout support, it requires
PHP 4 Beta 4 or later. Snoopy was developed and tested with PHP 3.0.12.
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.
CLASS VARIABLES: (default value in parenthesis)
$host the host to connect to
$port the port to connect to
$proxy_host the proxy host to use, if any
$proxy_port the proxy port to use, if any
$agent the user agent to masqerade as (Snoopy v0.1)
$referer referer information to pass, if any
$cookies cookies to pass if any
$rawheaders other header info to pass, if any
$maxredirs maximum redirects to allow. 0=none allowed. (5)
$offsiteok whether or not to allow redirects off-site. (true)
$expandlinks whether or not to expand links to fully qualified URLs (true)
$user authentication username, if any
$pass authentication password, if any
$accept http accept types (image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, )
$error where errors are sent, if any
$response_code responde code returned from server
$headers headers returned from server
$maxlength max return data length
$read_timeout timeout on read operations (requires PHP 4 Beta 4+)
set to 0 to disallow timeouts
$timed_out true if a read operation timed out (requires PHP 4 Beta 4+)
$maxframes number of frames we will follow
$status http status of fetch
$temp_dir temp directory that the webserver can write to. (/tmp)
$curl_path system path to cURL binary, set to false if none
EXAMPLES:
Example: fetch a web page and display the return headers and
the contents of the page (html-escaped):
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->user = "joe";
$snoopy->pass = "bloe";
if($snoopy->fetch("http://www.slashdot.org/"))
{
echo "response code: ".$snoopy->response_code."<br>\n";
while(list($key,$val) = each($snoopy->headers))
echo $key.": ".$val."<br>\n";
echo "<p>\n";
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
}
else
echo "error fetching document: ".$snoopy->error."\n";
Example: submit a form and print out the result headers
and html-escaped page:
include "Snoopy.class.php";
$snoopy = new Snoopy;
$submit_url = "http://lnk.ispi.net/texis/script-xs/msearch/netsearch.html";
$submit_vars["q"] = "amiga";
$submit_vars["submit"] = "Search!";
$submit_vars["searchhost"] = "Altavista";
if($snoopy->submit($submit_url,$submit_vars))
{
while(list($key,$val) = each($snoopy->headers))
echo $key.": ".$val."<br>\n";
echo "<p>\n";
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
}
else
echo "error fetching document: ".$snoopy->error."\n";
Example: showing functionality of all the variables:
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->proxy_host = "my.proxy.host";
$snoopy->proxy_port = "8080";
$snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)";
$snoopy->referer = "http://www.microsnot.com/";
$snoopy->cookies["SessionID"] = 238472834723489l;
$snoopy->cookies["favoriteColor"] = "RED";
$snoopy->rawheaders["Pragma"] = "no-cache";
$snoopy->maxredirs = 2;
$snoopy->offsiteok = false;
$snoopy->expandlinks = false;
$snoopy->user = "joe";
$snoopy->pass = "bloe";
if($snoopy->fetchtext("http://www.phpbuilder.com"))
{
while(list($key,$val) = each($snoopy->headers))
echo $key.": ".$val."<br>\n";
echo "<p>\n";
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
}
else
echo "error fetching document: ".$snoopy->error."\n";
Example: fetched framed content and display the results
include "Snoopy.class.php";
$snoopy = new Snoopy;
$snoopy->maxframes = 5;
if($snoopy->fetch("http://www.ispi.net/"))
{
echo "<PRE>".htmlspecialchars($snoopy->results[0])."</PRE>\n";
echo "<PRE>".htmlspecialchars($snoopy->results[1])."</PRE>\n";
echo "<PRE>".htmlspecialchars($snoopy->results[2])."</PRE>\n";
}
else
echo "error fetching document: ".$snoopy->error."\n";
COPYRIGHT:
Copyright(c) 1999,2000 ispi. All rights reserved.
This software is released under the GNU General Public License.
Please read the disclaimer at the top of the Snoopy.class.php file.
THANKS:
Special Thanks to:
Peter Sorger <sorgo@cool.sk> help fixing a redirect bug
Andrei Zmievski <andrei@ispi.net> implementing time out functionality
Patric Sandelin <patric@kajen.com> help with fetchform debugging
Carmelo <carmelo@meltingsoft.com> misc bug fixes with frames
여튼.. 세상엔 없는게 없는거같다.
프로그래머로써 너무 편해지고 있다.
집안일이 힘들것같아서 세탁기며 청소기며 집안에 들여놔줬더니 더 게을러지는 주부같다고나 할까? ㅋㅋ
그럼.. 파이썬은 안녕~ 다음에 언제 또 필요해질지 모르겟지만 이제는 나에게 무용해졌구나.. 그동안 고생했어.
'웹프로그램' 카테고리의 다른 글
PHP 파일 다운받을때 한글파일문제 해결방법 (0) | 2008.10.19 |
---|---|
PHP Encrypt/Decrypt (0) | 2008.10.19 |
PHP $_SERVER 함수 (0) | 2008.10.19 |
PHP 웹에서 엑셀문서 작업 (0) | 2008.10.19 |
PHP 배열로 된 테이블의 값을 담은 값으로 테이블 만들기 (0) | 2008.10.19 |
PHP The 30 Minute Regex Tutorial (0) | 2008.10.19 |
PHP 배열 지정한 위치부터 입력하기 (0) | 2008.10.19 |
PHP 배열에 지정한 이름으로 값을 담아두기 (0) | 2008.10.19 |