for($i=$start_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); // 发送一个常规的Post请求
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string );
$data = curl_exec($ch);
preg_match_all(‘/id=”table1″>[s]*?
[s]*?[sS]*?[s]*?/’, $data, $matches);if (!$handle = fopen($filename, ‘a+’)) {
echo “不能打开文件 $filename”;
echo “n”;
exit;
}
if (fwrite($handle, $matches[0][1]) === FALSE) {
echo “不能写入到文件 $filename”;
echo “n”;
exit;
}
echo “成功地将 $somecontent 写入到文件$filename”;
echo “n”;
fclose($handle);
curl_close($ch);
}