#!/usr/local/php/bin/php <?php $runtime = new runtime (); $runtime->start (); $cookie _jar = Tempnam ('/tmp ', ' Cookie ');
$filename = $argv [1]; $start _num= $argv [2]; $end _num = $argv [3];
for ($i = $start _num; $i < $end _num; $i + +) { $zip = sprintf (' 6s ', $i);
$fields _post = Array ( ' Postcode ' = $zip, ' Querykind ' = 2, ' Reqcode ' = ' gotosearch ', ' Search_button.x ' =>37, ' Search_button.y ' =>12 );
$fields _string = http_build_query ($fields _post, ' & '); $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, "url?reqcode=gotosearch&querykind=2&postcode=". $zip); curl_setopt ($ch, Curlopt_header, true); curl_setopt ($ch, Curlopt_returntransfer, true); curl_setopt ($ch, Curlopt_post, true); curl_setopt ($ch, Curlopt_connecttimeout, 120); curl_setopt ($ch, Curlopt_referer, $refer); curl_setopt ($ch, Curlopt_httpheader, $headers _login); curl_setopt ($ch, Curlopt_cookiefile, $cookie _jar); curl_setopt ($ch, Curlopt_cookiejar, $cookie _jar); curl_setopt ($ch, curlopt_useragent, $_server[' http_user_agent '); curl_setopt ($ch, Curlopt_post, 1); Send a regular POST request curl_setopt ($ch, Curlopt_postfields, $fields _string);
$data = curl_exec ($ch); Preg_match_all ('/id= ' table1 ">[s]*?<tr>[s]*?<td class=" Maintext ">[ss]*?</td>[s]*?</tr >/', $data, $matches); if (! $handle = fopen ($filename, ' A + ')) { echo "Cannot open file $filename"; echo "n"; Exit }
if (fwrite ($handle, $matches [0][1]) = = = = FALSE) { echo "Cannot write to file $filename"; echo "n"; Exit }
echo "successfully wrote $somecontent to file $filename"; echo "n";
Fclose ($handle); Curl_close ($ch); }
Class runtime { var $StartTime = 0; var $StopTime = 0; function Get_microtime () { List ($usec, $sec) =explode (", Microtime ()); return (float) $usec + (float) $sec); } function Start () { $this->starttime= $this->get_microtime (); } function Stop () { $this->stoptime= $this->get_microtime (); } function spent () { Return ($this->stoptime-$this->starttime); } }
$runtime->stop ();
$con = ' processed in '. $runtime->spent (). ' Seconds '; echo ' processed in '. $runtime->spent (). ' Seconds ';
|