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

标签 php asp.net curl web-scraping

我尝试了 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 一起使用

关于php - 使用 curl 从 asp.net 页面获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20835919/

相关文章:

asp.net - 使用 AddWithValue 插入 - 抛出错误?

使用 orderByChild 和 equalTo 来冰壶 Firebase?

php - Mysql/注释看/垂直

php - 使用 session 数据将帖子链接到用户 ID

添加母版页后 JavaScript 不工作

c# - 如何在C#中加密/解密url

php - 插入语句中的 MySql 表标识符

php - 如何命名二维复选框?

node.js - 从nodejs中的请求模块调用时,github搜索api没有给出结果

c++ - 来自curl库的内存泄漏