1 Star 1 Fork 0

Paul / GetMoocList

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
doAction.php 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
Paul 提交于 2018-05-12 18:41 . 修改慕课网的改版后失效的bug
<?php
/**
* 获取慕课网某个课程的列表章节
*/
/**
* 获取列表
* @param $url
* @param $is_title
* @return array
* @throws Exception
*/
function GetList($url, $is_title)
{
if (empty($url)) {
throw new Exception('链接为空');
}
$content = file_get_contents($url);
$pattern = '/<i\sclass="imv2-play_circle\stype"><\/i\>\s+(.*)\n/';
preg_match_all($pattern, $content, $res);
$res = isset($res[1]) ? $res[1] : '';
if (empty($res)) {
throw new Exception('获取不到当前页面的列表');
}
$result = [];
// 对字符串进行去除首尾空白符以及加上markdown的标题
foreach ($res as $key => $value) {
if ($is_title) {
$result[] = '## ' . trim($value);
} else {
$result[] = trim($value);
}
}
return $result;
}
try {
$url = trim($_POST['url']);
$is_title = intval($_POST['is_title']);
$is_title = $is_title == 0 ? 0 : 1;
$result = GetList($url, $is_title);
$result = [
'data' => $result,
'status' => 1
];
echo json_encode($result);
exit();
} catch (Exception $e) {
echo json_encode(['data' => $e->getMessage(), 'status' => 0]);
exit();
}
PHP
1
https://gitee.com/paultest/GetMoocList.git
git@gitee.com:paultest/GetMoocList.git
paultest
GetMoocList
GetMoocList
master

搜索帮助