[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Download files using python?

Posted on 2005-04-09
2
Medium Priority
?
545 Views
Last Modified: 2010-04-16
Is there a way to have python download and save files from the internet, if I can give it the url?  I would need the steps necessary for both getting the file and saving it somewhere.

Thanks in advance!
0
Comment
Question by:jonnyz0109
2 Comments
 
LVL 14

Accepted Solution

by:
RichieHindle earned 500 total points
ID: 13746958
Here's how to do it:

import urllib2
input = urllib2.urlopen('http://google.com/')
output = open('google.html', 'wb')
output.write(input.read())

That will download and save an HTML page - the same script will work for a binary file as well.
0
 
LVL 4

Author Comment

by:jonnyz0109
ID: 13747005
Excellent, thanks!  :o)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question