本帖最后由 comcn 于 2022-10-20 10:41 编辑
目标网址:https://www.aliyundrive.com/s/eLTrq8rJNmB/folder/62e32a7063a8ffeefb2e4e0dba497c82b148b5ed
我试了阿里网盘还有其他网址,curl只能获取“查看网页源代码”的内容,我想要获取F12中的所有dom元素,比如:
我的代码,基于tp
[PHP] 纯文本查看 复制代码 public function index()
{
$headers = [
"User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36",
"cookie:xxxxxxxxxxxxxx"];
$se=$this->curl('https://www.aliyundrive.com/s/eLTrq8rJNmB/folder/62e32a7063a8ffeefb2e4e0dba497c82b148b5ed',$headers);
dump($se);
}
public function curl($url, $headers = [])
{
$header = ['User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'];
$con = curl_init((string)$url);
curl_setopt($con, CURLOPT_HEADER, false);
curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($con, CURLOPT_RETURNTRANSFER, true);
curl_setopt($con, CURLOPT_ENCODING ,'gzip'); //加入gzip解析
if (!empty($headers)) {
curl_setopt($con, CURLOPT_HTTPHEADER, $headers);
} else {
curl_setopt($con, CURLOPT_HTTPHEADER, $header);
}
curl_setopt($con, CURLOPT_TIMEOUT, 5000);
$result = curl_exec($con);
return $result;
}
运行结果:
我想要的:
比如我要获取页面中的“来晚啦,该分享已失效”,url输入一个网盘链接,判断是否失效,但是curl获取不到“来晚啦,该分享已失效”元素
请问是没有设置header头问题吗?另外有php curl教程视频吗,b站不知道哪个好?
|