Using PHP to download a web page is a simple example code. 1. how to save the current page and enter segmentfault. comq10... in the browser to open this page. then, it is very easy to download the page using php in the console varcontentdocument. getE...
$url='https://segmentfault.com/q/1010000000149454'; $data=file_get_contents($url); $target=fopen('/tmp/test.html',"w"); fwrite($target, $data); fclose($target);
$ Url is downloaded locally and saved as a/tmp/test.html file.
1. how to save the current page
Enter
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 use javascript to save it in the/tmp/test.html file?
Document.exe cCommand ('saveas', false, '/tmp/test.htm ');
False
2. How to save any webpage?
This can be done with php above. what about javascript?
Reply content:
It's easy to download web pages with php
$url='https://segmentfault.com/q/1010000000149454'; $data=file_get_contents($url); $target=fopen('/tmp/test.html',"w"); fwrite($target, $data); fclose($target);
$ Url is downloaded locally and saved as a/tmp/test.html file.
1. how to save the current page
Enter
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 use javascript to save it in the/tmp/test.html file?
Document.exe cCommand ('saveas', false, '/tmp/test.htm ');
False
2. How to save any webpage?
This can be done with php above. what about javascript?
In browsers, your requirements are difficult to implement due to security factors.
It can be implemented in nodejs.