It’s easy to download web pages with php
<code> $url='https://segmentfault.com/q/1010000000149454'; $data=file_get_contents($url); $target=fopen('/tmp/test.html',"w"); fwrite($target, $data); fclose($target); </code>
$url is downloaded locally and saved as /tmp/test.html file.
1. How to save the current page
Enter in the browser
https://segmentfault.com/q/10...
Open this webpage
Then, in the console
var content = document.getElementsByTagName("html") [0].outerHTML;
content is the content of this webpage. How can I save it in the /tmp/test.html file using javascript?
document.execCommand('Saveas',false,'/tmp/test.htm');
false
2. How to save any web page?
This can be done using the php above, what about javascript?
It’s easy to download web pages with php
<code> $url='https://segmentfault.com/q/1010000000149454'; $data=file_get_contents($url); $target=fopen('/tmp/test.html',"w"); fwrite($target, $data); fclose($target); </code>
$url is downloaded locally and saved as /tmp/test.html file.
1. How to save the current page
Enter in the browser
https://segmentfault.com/q/10...
Open this webpage
Then, in the console
var content = document.getElementsByTagName("html") [0].outerHTML;
content is the content of this webpage. How can I save it in the /tmp/test.html file using javascript?
document.execCommand('Saveas',false,'/tmp/test.htm');
false
2. How to save any web page?
This can be done using the php above, what about javascript?
In the browser, your request is difficult to implement due to security factors.
You can consider implementing it in nodejs.