Home > Backend Development > PHP Tutorial > javascript - Download webpage with js?

javascript - Download webpage with js?

WBOY
Release: 2016-10-10 11:56:12
Original
1554 people have browsed it

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>
Copy after login
Copy after login

$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?

Reply content:

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>
Copy after login
Copy after login

$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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template