#! /Usr/local/php/bin/php <? Php $ Runtime = new runtime (); $ Runtime-> start (); $ Cookie_jar = tempnam ('/tmp', 'cooke ');
$ 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' => 'goopsearch ', '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 ); Currochelle 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 "the file $ filename cannot be opened "; Echo "n "; Exit; }
If (fwrite ($ handle, $ matches [0] [1]) === FALSE ){ Echo "cannot be written to file $ filename "; Echo "n "; Exit; }
Echo "successfully writes $ somecontent to the 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 ';
|