zoukankan      html  css  js  c++  java
  • 从指定URL中下载文件

     1 #!/usr/bin/env python3
     2 import requests
     3 
     4 def download(url):
     5     try:
     6         req = requests.get(url)
     7     except requests.exceptions.MissingSchema:
     8         print('Invalid URL "{}"'.format(url))
     9         return
    10 
    11     if req.status_code == 403:
    12         print('You do not have the authority to access this page.')
    13         return
    14     filename = url.split('/')[-1]
    15     with open(filename,'w') as fobj:
    16         fobj.write(req.content.decode('utf-8'))
    17     print("Download over.")
    18 
    19 if __name__ == '__main__':
    20     url = input('Enter a URL: ')
    21     download(url)
  • 相关阅读:
    感想2
    感想1
    记录4
    记录3
    记录2
    记录1
    库存物资管理系统-测试
    开学测试
    大二下开学测试有感
    大二下周总结一
  • 原文地址:https://www.cnblogs.com/--lr/p/11857996.html
Copyright © 2011-2022 走看看