AttributeError: 'module' object has no attribute 'urlretrieve'

后端 未结 3 1072
长发绾君心
长发绾君心 2020-12-07 12:17

I am trying to write a program that will download mp3\'s off of a website then join them together but whenever I try to download the files I get this error:

         


        
3条回答
  •  悲&欢浪女
    2020-12-07 12:59

    A Python 2+3 compatible solution is:

    import sys
    
    if sys.version_info[0] >= 3:
        from urllib.request import urlretrieve
    else:
        # Not Python 3 - today, it is most likely to be Python 2
        # But note that this might need an update when Python 4
        # might be around one day
        from urllib import urlretrieve
    
    # Get file from URL like this:
    urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3")
    

提交回复
热议问题