【求助】php使用curl類比post提交資料擷取目標網站資訊,求解?

來源:互聯網
上載者:User
代碼如下,但是沒有擷取到搜尋這個$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);
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.