<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<META name="description" content="">
<meta name="keywords" content="">
<title>Amazon</title>
</head>
<body>
<?php
$url = "http://www.amazon.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
echo $data = curl_exec($ch);
?>
</body>
这将在已经可以访问 www.amazon.com 的计算机上显示整个网页。 但如果计算机无法访问 amazon.com 域,则大部分内容(图片、脚本)将不可用,因为 $data 仅包含网页的 html 源。 我想知道是否有一种简单的方法可以让 curl(或 PHP)以“右键单击 - 另存为 - 网页完成”的方式获取网页的所有内容并在浏览器中显示。
最佳答案
据我所知,curl 没有递归下载的选项。我找到了 this answer这解决了问题,但仅适用于 curl cmd 工具。但是正如您所见,您必须先下载首页,解析链接,然后再使用 curl 下载它们。这也是 chrome、firefox 等在您保存网页时所做的。
关于php - curl PHP : How can I fetch all content of a web page and display it the way a browser does?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30524814/