私はPHPでデータのスクレイピングを試みていますが、アクセスする必要のあるURLには投稿データが必要です。私は、実際の情報は、それが応答データをロードに失敗しまし返すホストされている2番目の$ URLにアクセスしようとしたが、それは私がNCAAホームページにアクセスできるようになりますPHP cURLが応答データを読み込めませんでした
<?php
//set POST variables
$url = 'https://www.ncaa.org/';
//$url = 'https://web3.ncaa.org/hsportal/exec/hsAction?hsActionSubmit=searchHighSchool';
// This is the data to POST to the form. The KEY of the array is the name of the field. The value is the value posted.
$data_to_post = array();
$data_to_post['hsCode'] = '332680';
$data_to_post['state'] = '';
$data_to_post['city'] = '';
$data_to_post['name'] = '';
$data_to_post['hsActionSubmit'] = 'Search';
// Initialize cURL
$curl = curl_init();
// Set the options
curl_setopt($curl,CURLOPT_URL, $url);
// This sets the number of fields to post
curl_setopt($curl,CURLOPT_POST, sizeof($data_to_post));
// This is the fields to post in the form of an array.
curl_setopt($curl,CURLOPT_POSTFIELDS, $data_to_post);
//execute the post
$result = curl_exec($curl);
//close the connection
curl_close($curl);
?>
。正しいフォームデータを送信していても応答データを読み込めないという理由がありますか?
それはあなたが、私はそれの例を持っていることは、ポスト –
を投稿しない必要と思われますどうもありがとうございました。これは私が必要とするように正確に動作します。これはphpのcURLに関する私の研究に役立ちます。 – Cesarg219
@SunilPachlangia – Cesarg219