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

Discussion in 'Python' started by dongdong, Mar 8, 2006.

  1. dongdong

    dongdong Guest

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

    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"
     
    dongdong, Mar 8, 2006
    #1
    1. Advertising

  2. dongdong

    James Stroud Guest

    dongdong wrote:
    > I wrote as following:
    > content=urllib2.urlopen("http://www.sdfagfa.org/asasg/a.zip").read()
    > f=open("d:\\a.zip",'a+',1)
    > f.writelines(content)
    >
    > 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"
    >


    f=open("d:\\a.zip",'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.zip",'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

    http://www.jamesstroud.com/
     
    James Stroud, Mar 8, 2006
    #2
    1. Advertising

  3. dongdong

    dongdong Guest

    thank james;
    and I have got a way to resolve it :
    urllib.urlretrieve('http://x.x.x.x/library.zip','library.zip')
     
    dongdong, Mar 8, 2006
    #3
  4. dongdong

    dongdong Guest

    but I want to ask: how to find out explaination about the parameters of
    'open()' function?
     
    dongdong, Mar 8, 2006
    #4
  5. On 7 Mar 2006 22:08:21 -0800, "dongdong" <>
    declaimed the following in comp.lang.python:

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


    Uhm... Read the Python Library documentation?

    Or type "help(open)" at a Python interpreter console prompt...
    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
     
    Dennis Lee Bieber, Mar 8, 2006
    #5
  6. dongdong

    dongdong Guest

    thanks a lot.
     
    dongdong, Mar 8, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. abcd
    Replies:
    7
    Views:
    538
    Edward Elliott
    May 1, 2006
  2. fj
    Replies:
    10
    Views:
    883
    Jonathan N. Little
    Dec 5, 2006
  3. Tim

    7-zip or rar lib?

    Tim, Nov 17, 2005, in forum: Ruby
    Replies:
    4
    Views:
    114
    Josef 'Jupp' SCHUGT
    Nov 18, 2005
  4. Vilmos Soti

    File::MMagic doesn't recognize rar file

    Vilmos Soti, May 16, 2006, in forum: Perl Misc
    Replies:
    5
    Views:
    148
    A. Sinan Unur
    May 17, 2006
  5. PerlFAQ Server
    Replies:
    0
    Views:
    138
    PerlFAQ Server
    Apr 9, 2011
Loading...

Share This Page