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

JDBurnZ commented: Very good question, not one that you're probably going to easily track down by browsing the Python documentation. +0

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

Mark this as solved, please :)

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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.