6

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;

1 Answer 1

2

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

2
  • 1
    No, actually i was formatting question here @Stackoverflow and it's just a formatting error, in the actual code there is no error. Site is is in ASP.net and doing _dopostback to get content and i think there is some problem, i can't getting data because of javascript dopostback function. i don't know how to fix that problem.
    – MehulJoshi
    Dec 30, 2013 at 9:00
  • If the data is pulled with ajax, you could use the DeveloperTools of your browser and monitor the send data to determine the correct url, method and params. In your case, you have to send a POST request and add a lot of data. Perhabs, you have to parse the content of https://tennislink.usta.com/tournaments/rankings/rankinghome.aspx to add all necessary hidden filds for the post request
    – Philipp
    Dec 30, 2013 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.