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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看