Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data from asp.net page using curl

I tried file_get_content and curl to get page data that shows when I open it in browser but get nothing.

URL opens in browser but when I use curl I redirected to home page, what method I use to complete grab page with all data in my response.

    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;
like image 847
MehulJoshi Avatar asked Dec 30 '13 08:12

MehulJoshi


1 Answers

Are you sure, your url is correct? there's an whitesapce char between & and SectionDistrict

You can try it again with the following

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

This url should also work with file_get_contents

like image 165
Philipp Avatar answered Nov 04 '22 22:11

Philipp