|
先道声谢谢了。
视频演示:https://thumbsnap.com/qkDgKM5o
网址信息:https://www.toutiao.com/video/7418557232318513703/
我使用PHP的url获取一个网页的时候,它的网页内容一直在跳动,不能获取完整,我知道可能是使用了js动态创建的,但有技术或方法可以获取完整的内容吗?谢谢了
[ol]/* * 今日头条video页面的文件头 **/function toutiao_html_header($url){ $header = array( "Host: https://www.toutiao.com", "Referer: {$url}", "set-cookie: tt_webid=7421001700129736202; path=/; expires=Sun, 09 Feb 2025 04:22:07 GMT; domain=toutiao.com; secure; httponly", 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Accept-Language:zh-CN,zh;q=0.9,en;q=0.8', 'cookie: ******************************************************************************', "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36", ); return $header;}/** * 模拟浏览器开始访问请求,这个用于今日头条视频的页面内容获取 */function fetch_toutiao_video_html($url){ $header = toutiao_html_header($url); $timeout = 40; $ch = curl_init($url); curl_setopt($ch, CURLOPT_FAILONERROR, true); //设置请求头信息 #curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_HEADER, $header); //不取得返回头信息 #curl_setopt($ch, CURLOPT_HEADER, 0); // 关闭https验证 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_ENCODING, ""); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_REFERER, $header[1]); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_USERAGENT, $header[6]); $content = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } else { return $content; } curl_close($ch);}[/ol]复制代码 |
|