JavaScript-download Web pages with JS?

Source: Internet
Author: User
Downloading Web pages in PHP is simple

        $url='https://segmentfault.com/q/1010000000149454';    $data=file_get_contents($url);     $target=fopen('/tmp/test.html',"w");    fwrite($target, $data);        fclose($target);    

The $url is downloaded locally and saved as a/tmp/test.html file.

1. How to save the current page
Enter in the browser
HTTPS://SEGMENTFAULT.COM/Q/10 ...
Open this page
Then, in the console
var content = document.getElementsByTagName ("html") [0].outerhtml;
Content is the contents of this page, how can I use JavaScript to save it in the/tmp/test.html file?
Document.execcommand (' Saveas ', false, '/tmp/test.htm ');
False
2. How do I save any page?
This can be done with PHP above, JavaScript?

Reply content:

Downloading Web pages in PHP is simple

        $url='https://segmentfault.com/q/1010000000149454';    $data=file_get_contents($url);     $target=fopen('/tmp/test.html',"w");    fwrite($target, $data);        fclose($target);    

The $url is downloaded locally and saved as a/tmp/test.html file.

1. How to save the current page
Enter in the browser
HTTPS://SEGMENTFAULT.COM/Q/10 ...
Open this page
Then, in the console
var content = document.getElementsByTagName ("html") [0].outerhtml;
Content is the contents of this page, how can I use JavaScript to save it in the/tmp/test.html file?
Document.execcommand (' Saveas ', false, '/tmp/test.htm ');
False
2. How do I save any page?
This can be done with PHP above, JavaScript?

Browser, because of security factors, your requirements are difficult to achieve.
You can consider implementing it in Nodejs.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.