本帖最后由 ぅ初秋 于 2022-8-25 09:07 编辑
大佬勿喷说明
看论坛中许多大佬写了python版本,搜索了下没发现php的,新手不才,整个php的给大伙用
代码
[PHP] 纯文本查看 复制代码
<?php
//需引用QueryList来解析获取到的文本
use QL\QueryList;
public function index(){
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
$ql = QueryList::get('https://www.163.com/dy/media/T1603594732083.html', null, [
'headers' => [
'Host' => 'www.163.com',
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
]
]);
$href = $ql->find('.tab_content>.list_box>li>a')->attrs('href');
$today_url = $href[0];
$qlb = QueryList::get($today_url, null, [
'headers' => [
'Host' => 'www.163.com',
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
]
]);
$html = $qlb->find('.post_body>p:eq(1)')->html();
$new_thml = explode('<br>',$html);
unset($new_thml[0]);
unset($new_thml[1]);
unset($new_thml[array_key_last($new_thml)]);
$string = '';
foreach ($new_thml as $k => $v){
$string .= $v.PHP_EOL;
}
$key = 企业微信的企业ID.应用凭证密钥.应用ID.部门ID.用户ID(用户id未填则默认整个部门) //这些参数可以在企业微信中取到
$this->httpCurl('鉴于发布后服务器一直被打,就不提供了','post','json',array('key'=>$key,'msg'=>$string));
}
public function httpCurl($url, $type = 'get', $res = 'json', $arr = '') {
//1.初始化curl
$ch = curl_init();
//2.设置curl的参数
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($type == 'post') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
}
//3.采集
$output = curl_exec($ch);
//4.关闭
curl_close($ch);
return $output;
}
?>
如果刚好对你有用,打个分,谢谢 |