Javascript-use javascript to download webpages?

Source: Internet
Author: User
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.

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.