PHP crawling script

Posted: October 22, 2011 in PHP
<?
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,"http://www.siteurl.com");//http://www.autofind.com/dealer/details/3421.passenger/JH4KA9653YC010317/
	curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	$result=curl_exec ($ch);
	curl_close ($ch);
	
	
	function getStringBetween($string, $startText,$endText)
	{
		$start_pos =  strpos($string,$startText);	
		if($start_pos=="")
			return "";		
		$rest_string = substr($string, $start_pos + strlen($startText), strlen($string) );	
		$end_pos = strpos($rest_string,$endText );
		if($end_pos=="")
			return "";
		return $middle = substr( $string , $start_pos+ strlen($startText), $end_pos ); 
	}

	//====== title ===========
	preg_match_all ("/<font face=\"arial\" class=\"search_title\"><strong>([^`]*?)<\/strong><\/font>/", $result, $output);	
	foreach( $output as $item )	
	{
		$title = strip_tags($item[0]);	
		echo '<br />Title:'.$title;
		break;	
	}
	
	//====== Description ===========
	$start= '<!-- START MEDIA REVIEWS -->';
	$end = "<!-- END MEDIA REVIEWS -->";
	$middle = getStringBetween($data, $start, $end);
	echo '<br />Description:'.$middle;
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s