【发布时间】:2020-10-09 14:46:12
【问题描述】:
当我使用 curl 或 file_get_contents 下载 html 时,我没有得到 https://www.tumbex.com/memes.tumblr/posts?page=2
和代码(第一次尝试)
$html = file_get_contents('https://www.tumbex.com/memes.tumblr/posts?page=2');
和代码(第二次尝试)
$html = get_dataa('https://www.tumbex.com/memes.tumblr/posts?page=2');
echo($html);
function get_dataa($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
【问题讨论】:
-
该页面似乎正在运行 JavaScript 以更新 UI。检查浏览器调试工具中的网络选项卡,查看它发出的所有请求。对其进行逆向工程以抓取其数据,这将比仅抓取初始 HTML 涉及更多内容。
-
要查看该页面的卷曲效果,请禁用 JavaScript 并重新加载该页面。要解决这个问题,您可能需要阅读并理解以下内容:Tumblr API。