以下代码只用于个人娱乐,请勿用于商业用途,否则后果自负。
由于业余爱好,花了点时间用php+simple_html_dom 类库,简单实现了抓取好趣网的各卫视等直播源,simpleHtmlDOM类请至sourceforge官网下载
<?php/** * 获取好趣网视频直播源 * * Created by PhpStorm. * User: mac * Date: 2018/12/21 * Time: 上午11:32 */$base_url = 'http://www.haoqu.net'; $types = [// 1,//cctv频道 2,//卫视频道// 3,//省市频道// 4,//港澳频道// 5,//国外频道];include 'simplehtmldom/simple_html_dom.php';//$shd = new simple_html_dom();$chanel_urls = [];foreach ($types as $type) { $end_point = $base_url .'/'. $type .'/'; //获取频道列表 //$html = file_get_contents($end_point); $html = file_get_html($end_point); $all_a = $html->find('.p-item'); foreach ($all_a as $item) { $href = $item->children(0)->attr['href']; $url = $base_url . $href; $title = $item->children(0)->children[1]->children[0]->innertext; $title= iconv('gbk', 'utf-8', $title); //获取页面直播源 $chanel_page = file_get_html($url); $data_players = $chanel_page->find('[data-player]'); $dp_ids = []; foreach ($data_players as $dp) { $dp_id = $dp->attr['data-player']; $dp_url = 'http://www.haoqu.net/e/extend/tv.php?id=' . $dp_id; //这里我简单粗暴用了file_get_contents,大家可以用curl代替可以提升些速度 $tmp = file_get_contents($dp_url); $tmp = iconv('gbk', 'utf-8', $tmp); //从中找到signal $pattern = '/signal =[\s\S]*?;/'; preg_match($pattern, $tmp, $maches); if (isset($maches[0])) { $arr = explode('$', $maches[0]); $chanel_urls[$type][$title][] = $arr[1]; } } } }//时间仓促,这里直接打印出数据;有时间的同学可以存入文件或数据库var_dump($chanel_urls);
结果如下图:
QQ20181221-0.jpg
播放,简单的可以用VLC,大家可以下载试试
22.jpg
作者:又起风了_
链接:https://www.jianshu.com/p/5e41bfc07f1d