Mar 30 2010

PHP google images mini bot

Category: Php,Spiders & web botsGiulio Pons @ 1:34 pm

This simply php function will retrieve the links of the images from Google Images searched with a keyword. The function just calls images.google.it and parse the html to find the url of the images, in this case the urls are stored in the javascript, so the parsing doesn’t use any html tag to find data. It builds an array of urls and return it.

function getGoogleImg($k) {
	$url = "http://images.google.it/images?as_q=##query##&hl=it&imgtbs=z&btnG=Cerca+con+Google&as_epq=&as_oq=&as_eq=&imgtype=&imgsz=m&imgw=&imgh=&imgar=&as_filetype=&imgc=&as_sitesearch=&as_rights=&safe=images&as_st=y";
	$web_page = file_get_contents( str_replace("##query##",urlencode($k), $url ));

	$tieni = stristr($web_page,"dyn.setResults(");
	$tieni = str_replace( "dyn.setResults(","", str_replace(stristr($tieni,");"),"",$tieni) );
	$tieni = str_replace("[]","",$tieni);
	$m = preg_split("/[\[\]]/",$tieni);
	$x = array();
	for($i=0;$i<count($m);$i++) {
		$m[$i] = str_replace("/imgres?imgurl\\x3d","",$m[$i]);
		$m[$i] = str_replace(stristr($m[$i],"\\x26imgrefurl"),"",$m[$i]);
		$m[$i] = preg_replace("/^\"/i","",$m[$i]);
		$m[$i] = preg_replace("/^,/i","",$m[$i]);
		if ($m[$i]!="") array_push($x,$m[$i]);
	}
	return $x;
}

This function will be included in the next version of Mini Bot Class.

Share

Related posts:

  1. PHP bot to grab meteo information from Google
  2. Do spelling using google spell checker
  3. Mini Bot Class Updated
  4. PHP parse url, mailto, and also twitter’s usernames and arguments
  5. Bot that retrieves url meta data and other infos

Tags: , , , , , ,

3 Responses to “PHP google images mini bot”

  1. PHP Mini bot « My Blog says:

    [...] class with some new things: you can now retrive the list of videos from a Youtube user, you can retrieve the images return by Google Images when searched with a query and I’ve added some function to handle Twitter account through its [...]

  2. Samuil Banti says:

    Nice function :)

  3. web hosting says:

    Content like this is a good example of properly written informational material It’s easy to read and the points are stated in an intelligent way.

Leave a Reply