php采集 curl

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
リリース: 2016-06-06 20:26:30
オリジナル
1208 人が閲覧しました

使用curl采集,$url = 'http://kakaku.com/pc/';请问怎么修改下面的代码?

<code class="php"> function GetContent($url = "", $post_data = '', $method = 'POST', $timeout = 500) {
        if (is_array($post_data)) {
            $post_data = http_build_query($post_data);
        }
        if ($method == 'GET') {
            $url = $url . '?' . ltrim($post_data, '?');
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) \r\n Accept: */*'));
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        if ($method == 'POST') {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        }
        $content = curl_exec($ch);
        $response = curl_getinfo($ch);
        return $content;
    }</code>
ログイン後にコピー
ログイン後にコピー

回复内容:

使用curl采集,$url = 'http://kakaku.com/pc/';请问怎么修改下面的代码?

<code class="php"> function GetContent($url = "", $post_data = '', $method = 'POST', $timeout = 500) {
        if (is_array($post_data)) {
            $post_data = http_build_query($post_data);
        }
        if ($method == 'GET') {
            $url = $url . '?' . ltrim($post_data, '?');
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) \r\n Accept: */*'));
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        if ($method == 'POST') {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        }
        $content = curl_exec($ch);
        $response = curl_getinfo($ch);
        return $content;
    }</code>
ログイン後にコピー
ログイン後にコピー

指定 第三个参数 的值为 GET 就可以了.

php采集 curl

你是要采集get还是post请求的内容?

若是采集首页直接
echo file_get_contents('http://kakaku.com/pc/'); 即可

関連ラベル:
php
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
PHP 拡張子 intl
から 1970-01-01 08:00:00
0
0
0
phpのデータ取得?
から 1970-01-01 08:00:00
0
0
0
PHP GET エラー レポート
から 1970-01-01 08:00:00
0
0
0
phpを上手に学ぶ方法
から 1970-01-01 08:00:00
0
0
0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート