Snoopy example (PHP)


SUBMITTED BY: scripts4you

DATE: Oct. 21, 2015, 9 a.m.

FORMAT: Text only

SIZE: 1.4 kB

HITS: 1855

  1. include("snoopy.class.php");
  2. $snoopy = new Snoopy;
  3. // need an proxy?:
  4. //$snoopy->proxy_host = "my.proxy.host";
  5. //$snoopy->proxy_port = "8080";
  6. // set browser and referer:
  7. $snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
  8. $snoopy->referer = "http://www.jonasjohn.de/";
  9. // set some cookies:
  10. $snoopy->cookies["SessionID"] = '238472834723489';
  11. $snoopy->cookies["favoriteColor"] = "blue";
  12. // set an raw-header:
  13. $snoopy->rawheaders["Pragma"] = "no-cache";
  14. // set some internal variables:
  15. $snoopy->maxredirs = 2;
  16. $snoopy->offsiteok = false;
  17. $snoopy->expandlinks = false;
  18. // set username and password (optional)
  19. //$snoopy->user = "joe";
  20. //$snoopy->pass = "bloe";
  21. // fetch the text of the website www.google.com:
  22. if($snoopy->fetchtext("http://www.google.com")){
  23. // other methods: fetch, fetchform, fetchlinks, submittext and submitlinks
  24. // response code:
  25. print "response code: ".$snoopy->response_code."<br/>\n";
  26. // print the headers:
  27. print "<b>Headers:</b><br/>";
  28. while(list($key,$val) = each($snoopy->headers)){
  29. print $key.": ".$val."<br/>\n";
  30. }
  31. print "<br/>\n";
  32. // print the texts of the website:
  33. print "<pre>".htmlspecialchars($snoopy->results)."</pre>\n";
  34. }
  35. else {
  36. print "Snoopy: error while fetching document: ".$snoopy->error."\n";
  37. }

comments powered by Disqus