0

別のサイトから 1 つのページを解析しようとしています。それにはcUrlを使用します

リクエスト (データをスクリプトに送信):

        $.ajax({
            url: 'wordstat/ajax?query='+query+'&page='+page+'&id='+id,
            success: function(data){
                alert(data);
            }
        });

このスクリプト (wordstat/ajax) は、コントローラーを介して 2 番目のサイトに要求を行います。

コントローラ:

public function ajax()
{
    $this->model->auth();
    echo $this->model->parse_uri($_GET['page'],$_GET['query']);

}

モデル:

public function parse_uri($url,$word)
{
    curl_setopt($this->curl, CURLOPT_URL, "http://wordstat/rating.php?url=".$url."&word=".$word."&gap=3");

    $html = mb_convert_encoding(str_replace("\n","",curl_exec($this->curl)), "utf-8", "windows-1251");
    preg_match('/<span style="font-size:14px" class=red>(.*)<\/span>/U',$html,$matches);
    return $matches;
}

ブラウザに入れて http://localhost/wordstat/ajax?page=page&url=urlこのページを開くと、彼女<span style="font-size:14px" class=red>は別のサイトの値を正しく返します

しかし、私がAjaxリクエストを介してそれを行うと、常に空の配列が返されます

私は何を間違っていますか?下手な英語でごめんなさい

4

2 に答える 2

0

問題が解決しました

    $url = str_replace(" ","",$url);
    $word = str_replace(" ","",$word);

    curl_setopt($this->curl, CURLOPT_URL, "http://parser/rating.php?url=".$url."&word=".$word."&gap=3");

    $html = str_replace("\n","",curl_exec($this->curl));
    preg_match('/<span style="font-size:14px" class=red>(.*)<\/span>/U',$html,$matches);

    return $matches;

助けようとした人に感謝します

于 2013-07-10T04:05:49.533 に答える