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

后端 未结 3 1074
长发绾君心
长发绾君心 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 12:58

    As you're using Python 3, there is no urllib module anymore. It has been split into several modules.

    This would be equivalent to urlretrieve:

    import urllib.request
    data = urllib.request.urlretrieve("http://...")
    

    urlretrieve behaves exactly the same way as it did in Python 2.x, so it'll work just fine.

    Basically:

    • urlretrieve saves the file to a temporary file and returns a tuple (filename, headers)
    • urlopen returns a Request object whose read method returns a bytestring containing the file contents

提交回复
热议问题