简体   繁体   中英

Curl PHP: How can I fetch all content of a web page and display it the way a browser does?

<!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>

This would display the entire web page on a computer that has access to www.amazon.com already. But if the computer doesn't have access to amazon.com domain, most of the content (pictures, scripts) would be unavailable since $data contains only the html source of the web page. I wonder if there's an easy way for curl (or PHP) to fetch all content of a web page the way "right-click - save as - webpage complete" does and display it a browser does.

As far as I know curl does not have an option for recursive downloading. I found this answer which solves the problem but only for the curl cmd tool. But as you can see there you have to download the frontpage first, parse it for links and then use curl to download them as well. This is also what chrome, firefox etc do when you save a webpage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM