Python implementation save Web page to local example _python

Source: Internet
Author: User

Learn the Python example: implementing saving a Web page to a local

Copy Code code as follows:

#coding =utf-8
__auther__ = ' Xianbao '
Import Urllib
Import OS
def reporthook (Blocks_read, Block_size, total_size):
If not blocks_read:
print ' Open connection '
Return
If total_size < 0:
Print "%d is reading (%dbytes complete)"% (Blocks_read, Blocks_read * block_size)
Else
Amout_read = block_size * Blocks_read
print '%d is being read,%d/%d '% (Blocks_read, Amout_read, Total_size)
Return

Try
FileName, msg = urllib.urlretrieve (' http://www.jb51.net/', Reporthook=reporthook)
Print
print ' file is: ', filename
print ' header file is '
Print msg
print ' Before deleting the file address: ', os.path.exists (filename)

Finally
Urllib.urlcleanup ()

print ' File still exists: ', os.path.exists (filename)

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.