how to download a zip or rar file to local machine using python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dongdong

    #1

    how to download a zip or rar file to local machine using python?

    I wrote as following:
    content=urllib2 .urlopen("http://www.sdfagfa.org/asasg/a.zip").read()
    f=open("d:\\a.z ip",'a+',1)
    f.writelines(co ntent)

    the zip file has been download to my machine,but when be unzip , error
    occurs:
    " there is an error at the end of the file"

  • James Stroud

    #2
    Re: how to download a zip or rar file to local machine using python?

    dongdong wrote:[color=blue]
    > I wrote as following:
    > content=urllib2 .urlopen("http://www.sdfagfa.org/asasg/a.zip").read()
    > f=open("d:\\a.z ip",'a+',1)
    > f.writelines(co ntent)
    >
    > the zip file has been download to my machine,but when be unzip , error
    > occurs:
    > " there is an error at the end of the file"
    >[/color]

    f=open("d:\\a.z ip",'a+',1)

    Here you want to open a.zip as a text file (default) for appending, in
    both read and write mode.

    I think sufficient would be

    f=open("d:\\a.z ip",'wb')

    For opening a new file and writing as binary.

    Then you will want:

    f.write(content )

    f.close()

    James

    --
    James Stroud
    UCLA-DOE Institute for Genomics and Proteomics
    Box 951570
    Los Angeles, CA 90095


    Comment

    • dongdong

      #3
      Re: how to download a zip or rar file to local machine using python?

      thank james;
      and I have got a way to resolve it :
      urllib.urlretri eve('http://x.x.x.x/library.zip','l ibrary.zip')

      Comment

      • dongdong

        #4
        Re: how to download a zip or rar file to local machine using python?

        but I want to ask: how to find out explaination about the parameters of
        'open()' function?

        Comment

        • dongdong

          #5
          Re: how to download a zip or rar file to local machine using python?

          thanks a lot.

          Comment

          Working...