An “Extremely” Easy Way to Get Google Search Result by PHP (Not Using API)

Before Start, Cite some words from Bible: “Not only so, but we also rejoice in our sufferings, because we know that suffering produces perseverance; perseverance, character; and character, hope. And hope does not disappoint us, because God has poured out his love into our hearts by the Holy Spirit, whom he has given us.” Ro 5:3-5

 

I’d like to share a way to get Google search result by using a PHP program.

First, we don’t use Google API.

Second, we don’t not use the general Google search result page, like HERE, instead, we use a pretty tricky way, Google PDA search result :), like HERE.

Third, the structure of PDA-search result page is quite easy, and if you take a look at the program below, you will know it.

 

/* Here is a function get the Google-PDA-search result page, and return the all html code of the content */
				

function get_google_result ($key_word, $start)

{

        $temp_url = “http://www.google.cn/pda/search?mrestrict=xhtml&start=”.$start.“&q=site%3Akaoshi.wobuxihuan.org+”.$key_word;

        $ch = curl_init();

        $timeout = 0; // set to zero for no timeout

        curl_setopt ($ch, CURLOPT_URL, $temp_url);

        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

        curl_setopt ($ch, CURLOPT_REFERER, “http://www.google.com”);

        curl_setopt ($ch, CURLOPT_USERAGENT, “Mozilla/4.0 (compatible; PIE; ppc; SV1)”);

        $dpage = curl_exec($ch);

        curl_close($ch);

        return $dpage;

}

 

/* And here is the real vital part of this program */

function strip_google($content)

{
				

    $temp=split(‘<div class=”c1″>’,$content,2);
				

    $temp=‘<div class=”c1″>’.$temp[1];
				

    $temp=split(‘<div><a href=”/pda/’,$temp,2);
				

    $temp=$temp[0];
				

    $temp=split(‘<span class=”c2″>’,$temp,11);
					

    for($k=0;$k<10;$k++)

    {
				

    $result[$k]=$temp[$k];
				

    $te=split(‘</b>’,$result[$k],2);
				

    $result[$k]=$te[1];

    }
					

    return $result;

 

}
				

 

How to use these two functions?

Try: echo strip_google(get_google_result(”GRE”);

J

Enjoy it.

You welcome :0

There are no comments on this post

Leave a Reply

Blue Murder at St. Trinian'sBusterSeraphim FallsRicky Gervais Live 3: FameDeath Sentence