我通常依靠Curl來做這些事情。 而不是用按鈕發送表單來檢索源,直接調用響應頁面(給它你的請求)。因爲我在PHP下工作,所以這很容易。用python,你需要pycURL來管理同樣的事情。
所以唯一要做的就是調用venues.php,使用POST method with Curl引發的良好參數值。
這樣,您將需要準備您的請求(國家代碼,貓的名稱),但您不需要選中複選框,也不需要在瀏覽器中加載網站頁面。
set_ini(max_execution_time,1200) // wait 20 minutes before quitting
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://db.slickbox.net/venues.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
// prepare arguments for the form
$data = array('adlock ' => 1, 'age' => 0,'country' => 145,'imgcnt'=>0, 'lock'=>0,'regex'=>1,'submit'=>'Search','vname'=>'test');
//add arguments to our request
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//launch request
if(! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
echo $result;
您是否嘗試更改請求的超時時間? – Dekel
無論如何,在請求庫的情況下,這不是超時工作方式。這會設置返回異常之前等待的最長時間。問題是運行代碼時,這些庫中的任何一個都會立即返回結果,而不應該這樣做。 – DaJoNel