使用curl从asp.net页面获取数据

我试着用file_get_content和curl来获取页面数据,当我在浏览器中打开它时显示,但什么也没有。

URL在浏览器中打开,但是当我使用curl重定向到主页时,我用什么方法来完成抓取页面,并在响应中包含所有数据。

    function curl($url)
    {
      $agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:26.0) Gecko/20100101 Firefox/26.0";
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch, CURLOPT_USERAGENT, $agent);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      $data = curl_exec($ch);
      $info = curl_getinfo($ch);  
      print_r($info);
      echo "curl error".curl_error($ch);
      curl_close($ch);
      echo $data;
      return $data;
    }

    $secState = '70';
    $rankYear = 2013;
    $url = 'https://tennislink.usta.com/tournaments/rankings/rankinghome.aspx#Action=1&SectionDistrict='.$secState.'&Year='.$rankYear.'&Division=G8&ListType=0';
    echo $url;
    $html=curl($url);
    echo $html;

你确定,你的网址是正确的吗? &SectionDistrict之间有一个whitesapce字符

您可以使用以下方法重新尝试

    $url = 'https://tennislink.usta.com/tournaments/rankings/rankinghome.aspx#Action=1&SectionDistrict='.$secState.'&Year='.$rankYear.'&Division=G8&ListType=0';

这个URL也应该和file_get_contents工作

链接地址: http://www.djcxy.com/p/48605.html

上一篇: Get data from asp.net page using curl

下一篇: Curl PUT data is not received