douxuelv7755 2017-02-04 03:18
浏览 68
已采纳

php脚本获取动态加载的网站计划

I'm trying to make a php script which can take a specific tv channel schedule from a specific website written in Yii Framework. I'm trying to get the full HTML using php cURL but I can't find this section.

$curl = curl_init('http://port.hu/tv');
curl_setopt ($curl, CURLOPT_POSTFIELDS, 'id=tvchannel-3&date=2017-02-05'); // for example
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
$content = curl_exec($curl);
echo $content;

I tried before with php file_get_contents with the same result. Any idea? Thanks.

  • 写回答

1条回答 默认 最新

  • doucong1992 2017-02-04 05:15
    关注

    You cannot scrape directly from the website page, because looks like the website is using ajax (I guess) to load the data onto the page. So what I did, I monitor the Network activity on the page using Chrome Developer Tools, and I found this API url:

    http://port.hu/tvapi?channel_id=tvchannel-3&i_datetime_from=2017-02-05&i_datetime_to=2017-02-10

    It returned JSON strings, and the dev does not secure the API. So no need to scrape anymore, just load the JSON API directly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据