代碼如下,但是沒有擷取到搜尋這個$name關鍵詞應有的資料,求解?
$name="進擊的巨人";$url="http://www.4567.tv/search.asp";$data = array ( 'typeid'=>'2', 'keyword' => urlencode(mb_convert_encoding($name, "GBK","UTF-8")),); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $c=curl_exec($ch); curl_close($ch);
回複內容:
代碼如下,但是沒有擷取到搜尋這個$name關鍵詞應有的資料,求解?
$name="進擊的巨人";$url="http://www.4567.tv/search.asp";$data = array ( 'typeid'=>'2', 'keyword' => urlencode(mb_convert_encoding($name, "GBK","UTF-8")),); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $c=curl_exec($ch); curl_close($ch);
首先你必鬚根據抓包資料來確定POST的資料。假設你的POST方式和資料是沒有問題的,我只是根據你的代碼說出目前的問題。
修改後的代碼:
$name="進擊的巨人";$url="http://www.4567.tv/search.asp";$data = array ( 'typeid'=>'2', 'keyword' => mb_convert_encoding($name, "GBK","UTF-8"), //注意這裡);$data = http_build_query($data);//注意這裡$ch = curl_init();curl_setopt($ch, CURLOPT_URL,$url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1 );curl_setopt($ch, CURLOPT_POSTFIELDS, $data);$c=curl_exec($ch);curl_close($ch);
如果抓包正確,上述代碼不能正確執行的話,請根據具體的問題解決,通常可以嘗試添加Reffer/UserAgent等資訊。
urlencode 去掉
這是介面的請求例子吧?
應該沒有什麼問題,你把根憑證驗證關了試一下
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);