zoukankan      html  css  js  c++  java
  • python创建以日期命名的文件夹并向内写入文件 | 下载超星课程的PPT

    import os
    import requests
    import time
    import urllib.request
    
    #----获取时间----创建文件夹----
    tt = time.strftime("%Y%m%d---%H%M", time.localtime())
    #path = r"F:desktop爬取的图片"
    path = r"F:desktop"+'\'+tt+'爬虫'
    if not os.path.exists(path):
        os.makedirs(path)
        print('文件夹创建完成  '+path)
    #--------------存储目录创建结束----
    #------------Main------------------
    piclist = []
    for ii in range(1,500,1):
        url = 'https://s3.ananas.chaoxing.com/doc/1d/cc/2b/bc4c3ab388e75e8f42f9f7fedc087468/thumb/%i.png' % ii
        piclist.append(url)
    print(piclist)
    x = 1
    for http in piclist:
        print(http)
       # filesavepath = r'F:desktop爬取的图片\%s.jpg' % x
        filesavepath = path+'\%s.jpg' % x
        urllib.request.urlretrieve(http, filesavepath)
        x += 1
        print('正在保存第{:.0f}张图片'.format(x))
        time.sleep(1)

    转载仅为学习,不会商用。
    欢迎转载原创,附文链接。
  • 相关阅读:
    SQL中的union
    SQL的类型转换
    Keytool生成证书
    Openssl生成证书
    Python示例-Json Parse
    Python示例-TCP Port Scan
    Python套接字
    TCP端口扫描
    Linux环境变量
    Python示例-Logging
  • 原文地址:https://www.cnblogs.com/xdd1997/p/12526836.html
Copyright © 2011-2022 走看看