1

Wget is a very useful tool, however, I dont know how to use it in python. Below is my try but with no luck. Would you tell me the right way ? Thank you very much !!

I made a wwget.py

#!/usr/bin/python

import urllib2, urllib

img=wget("http://blog.freetimegears.com.tw/patrick/archives/Maple-tree.jpg")

Running in termial


:~/abc$ ./wwget.py
Traceback (most recent call last):
File "./wwget.py", line 5, in <module>
img=wget("http://blog.freetimegears.com.tw/patrick/archives/Maple-tree.jpg")
NameError: name 'wget' is not defined

Comments
Very good question, not one that you're probably going to easily track down by browsing the Python documentation.
4
Contributors
5
Replies
13
Views
8 Years
Discussion Span
Last Post by JDBurnZ
Featured Replies
  • If you're attempting to download a file in Python, it's very simple: [code] import urllib, os # if you comment out this line, it will download to the directory from which you run the script. os.chdir('/directory/to/save/the/file/to') url = 'http://www.mydomain.com/myfile.txt' urllib.urlretrieve(url) [/code] Read More

0

Thx sneekula and linux. I have tried and seems it is quite easy using linux's script to get the job done. Thanks.

2

If you're attempting to download a file in Python, it's very simple:

import urllib, os

# if you comment out this line, it will download to the directory from which you run the script.
os.chdir('/directory/to/save/the/file/to')

url = 'http://www.mydomain.com/myfile.txt'
urllib.urlretrieve(url)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.