Search code examples
phpsnoopy

How to use snoopy class in php


I've been trying to find out how to use snoopy class in php. I'm trying to search anything from google using snoopy. i found out that the form of google search is name=q and the action=/search

how to set my snoopy code to a correct code.

$s=new Snoopy();
$form=array("q"=>"spiderman");
$s->httpmethod = "GET";
$s->submit("http://www.google.com",$form);
echo $s->results;

i got a 405 result.


Solution

  • <?php
    // include snoopy library
    require('Snoopy.class.php');
    // initialize snoopy object
    $snoopy = new Snoopy;
    $url = "http://t.qq.com";
    // read webpage content
    $snoopy->fetch($url);
    // save it to $lines_string
    $lines_string = $snoopy->results;
    //output, you can also save it locally on the server
    echo $lines_string;
    ?>