如何使用cURL初始化函数修复307错误?

时间:2018-07-02 21:03:59

标签: php curl

运行以下代码时,返回307错误

if(isset($_GET['tag'])){
    $tag = strtoupper($_GET['tag']);
    $curl = curl_init("https://www.bloomberg.com/quote/".strtoupper($tag).":US");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $page = curl_exec($curl);

    if(curl_errno($curl)) // check for execution errors
    {
        echo 'Scraper error: ' . curl_error($curl);
        exit;
        echo '<script>alert("")</script>';
    }
    curl_close($curl);
    $regex = '/<span class="priceText__1853e8a5">(.*?)<\/span>/';
    echo $page;
    if ( preg_match($regex, $page, $list) ){
        $price = $list[0];
        $regex = '/<div class="value__b93f12ea">(.*?)<\/div>/';
        preg_match($regex, $page, $list);
        echo '<script>alert("'.$price.'")</script>';
    }
    include "fetch.php";
}

当我使用浏览器访问该网站时,可以看到该页面!有人可以帮我修复并了解发生了什么吗?谢谢!

0 个答案:

没有答案