我正在嘗試登錄到一個(gè)網(wǎng)站并重定向到數(shù)組中聲明的頁(yè)面。我成功登錄,我得到了數(shù)組中的第一個(gè)網(wǎng)址。但是問(wèn)題是,當(dāng)我第二次循環(huán)通過(guò)代碼時(shí),我遇到了錯(cuò)誤。代碼:$url = 'https://url/signin'; $ch = curl_init($url); $data = [ "e_mail" => "email@", "password" => "123456" ]; curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // allow redirections curl_setopt($ch, CURLOPT_POST, true); // we are making post request curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); // COOKIEEjAR To save data for cookies created for login process curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // TRUE means dont just echo output the data instead we can store the request response in some variaable $result = curl_exec($ch); $urls_to_loop = array('url1', 'url2');foreach ($urls_to_loop as $key => $url) { curl_setopt($ch, CURLOPT_URL, $url); $exec = curl_exec($ch); // echo($exec); curl_close($ch);// close login CURL resource, and free up system resources $html = new simple_html_dom(); $html->load($exec); $links = []; foreach($html->find('link') as $element){ if($element->href[-1] === '4'){ // check if url is not in the array if(!in_array($element->href, $links)){ array_push($links, $element->href); } } }}//END foreach這是錯(cuò)誤:警告:curl_setopt(): 提供的資源不是第 263 行 C:\xampp\htdocs\web\index.php中有效的 cURL 句柄資源警告:curl_exec(): 提供的資源不是第 264 行 C:\xampp\htdocs\web\index.php中有效的 cURL 句柄資源警告:curl_close(): 提供的資源不是第 267 行 C:\xampp\htdocs\web\index.php中有效的 cURL 句柄資源警告:curl_setopt(): 提供的資源不是第 263 行 C:\xampp\htdocs\web\index.php中有效的 cURL 句柄資源
1 回答

德瑪西亞99
TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊
您正在循環(huán)期間關(guān)閉處理程序。
curl_close($ch);
將該行移到腳本的末尾。
- 1 回答
- 0 關(guān)注
- 101 瀏覽
添加回答
舉報(bào)
0/150
提交
取消