I am fairly new to the latest verion of Python and using it on windows
95, 2000, and/or XP. What libraries, modules, functions, etc. would I
need to set up a Python script to download a file, say
"htttp://www.sound.com/files/bob.wav" to my own hard drive at
"c:\sound\bob.w av"?
I haven't found any good examples of such an operation in the
documentation at the Python website. Any suggestions are appreciated.
Thanks. 8 6576
On Wed, 15 Sep 2004 00:00:21 GMT Radioactive wrote: I am fairly new to the latest verion of Python and using it on windows 95, 2000, and/or XP. What libraries, modules, functions, etc. would I need to set up a Python script to download a file, say "htttp://www.sound.com/files/bob.wav" to my own hard drive at "c:\sound\bob.w av"?
I haven't found any good examples of such an operation in the documentation at the Python website. Any suggestions are appreciated. Thanks.
See: 11. Internet Protocols and Support
at http://python.org/doc/2.3.4/lib/lib.html
In this example, Yahoo uses 00=Jan, so 08=Sep... from urllib import urlopen URL1 = "http://ichart.finance. yahoo.com/table.csv?" URL2 = "s=IBM&a=08&b=1 4&c=2004&d=08&e =14&f=2004&g=d& ignore=.csv" urlopen("%s%s" % (URL1,URL2)).re adlines()
['Date,Open,High ,Low,Close,Volu me,Adj. Close*\n',
'14-Sep-04,86.60,86.88, 86.15,86.72,395 3500,86.72\n', '<!--
ichart9.finance .dcn.yahoo.com uncompressed Tue Sep 14 17:55:33 PDT 2004
-->\n']
Radioactive Man <rm@rm.rm> wrote: I am fairly new to the latest verion of Python and using it on windows 95, 2000, and/or XP. What libraries, modules, functions, etc. would I need to set up a Python script to download a file, say "htttp://www.sound.com/files/bob.wav" to my own hard drive at "c:\sound\bob.w av"?
Something like:
import urllib
urllib.urlretri eve( "htttp://www.sound.com/files/bob.wav",
'c:/sound/bob.wav')
should be fine.
I haven't found any good examples of such an operation in the documentation at the Python website. Any suggestions are appreciated. http://docs.python.org/lib/module-urllib.html has the docs of
urlretrieve, and it's SO simple that I don't really see what "good
examples" one might provide. A book that by design is full of examples
(hopefully good) is the Python Cookbook, which in the intro to Chapter
10 (Network Programming) gives a slightly richer example which downloads
several files with urllib.urlretri eve. http://www.python9.org/p9-zadka.ppt may have some useful pointers,
perhaps. http://www.experts-exchange.com/Prog...nguages/Python
/Q_21048439.html has exactly the same question you asked, but you have
to "sign up" to see the solution (always the same one).
Alex
On Wed, 15 Sep 2004 17:20:43 +0200, al*****@yahoo.c om (Alex Martelli)
wrote: Radioactive Man <rm@rm.rm> wrote:
I am fairly new to the latest verion of Python and using it on windows 95, 2000, and/or XP. What libraries, modules, functions, etc. would I need to set up a Python script to download a file, say "htttp://www.sound.com/files/bob.wav" to my own hard drive at "c:\sound\bob.w av"?
Something like:
import urllib urllib.urlretr ieve( "htttp://www.sound.com/files/bob.wav", 'c:/sound/bob.wav')
should be fine.
I haven't found any good examples of such an operation in the documentation at the Python website. Any suggestions are appreciated.
http://docs.python.org/lib/module-urllib.html has the docs of urlretrieve, and it's SO simple that I don't really see what "good examples" one might provide. A book that by design is full of examples (hopefully good) is the Python Cookbook, which in the intro to Chapter 10 (Network Programming) gives a slightly richer example which downloads several files with urllib.urlretri eve. http://www.python9.org/p9-zadka.ppt may have some useful pointers, perhaps.
http://www.experts-exchange.com/Prog...nguages/Python /Q_21048439.html has exactly the same question you asked, but you have to "sign up" to see the solution (always the same one).
Alex
Thanks to all who replied on this one. I have managed to download,
but somehow the file is getting mangled when I save it to my hard
drive. Here is the test script I came up with:
import urllib
f = urllib.urlopen( "http://www.python.org/pics/pythonHi.gif")
g = f.read()
file = open("trash.gif ", "w")
file.write(g)
file.close()
The file "trash.gif" is actually saved under "C:\Python2 3" in the
correct format (recognizable to *.gif viewing programs), but is so
severely mangled that I can't even recognize it visually. It happens
every time, so I do not believe it is a random event. My question
here is what am I doing wrong and at what stage is the file getting
mangled? I know this method works fine with text files, but for some
reason is damaging to binary files.
The same result happened when I substituted urllib.urlretri eve() for
urllib.urlopen( ).
On Fri, 17 Sep 2004 01:46:42 GMT, Radioactive Man <rm@rm.rm> wrote: Here is the test script I came up with:
import urllib f = urllib.urlopen( "http://www.python.org/pics/pythonHi.gif") g = f.read() file = open("trash.gif ", "w") file.write(g) file.close()
You're opening the output file in ascii mode, so newlines characters
are getting converted to the CR/LF combination. Change the second
parameter to open() to "wb".
On Fri, 17 Sep 2004 12:08:36 +1000, Andrew Durdin <ad*****@gmail. com>
wrote: On Fri, 17 Sep 2004 01:46:42 GMT, Radioactive Man <rm@rm.rm> wrote: Here is the test script I came up with:
import urllib f = urllib.urlopen( "http://www.python.org/pics/pythonHi.gif") g = f.read() file = open("trash.gif ", "w") file.write(g) file.close()
You're opening the output file in ascii mode, so newlines characters are getting converted to the CR/LF combination. Change the second parameter to open() to "wb".
That worked. Thanks.
Looking back through the documentation, I see that open() is really an
alias for file(). Are there any variants of the "open" commmand that
allow location (drive and directory) of the file to be specified as
well, for example, if I wanted to save the file as
"D:\binaries\tr ash.gif" instead of the default location? If that's
not possible, then the alternative might be exectuting commands from
the os module to accomplish the same thing.
Radioactive Man wrote: Looking back through the documentation, I see that open() is really an alias for file().
For now... but (despite what those docs imply) it's really best to stick
with using open() and don't worry about the existence of file() unless
you're trying to subclass it... (GvR has recently said that he never
intended for file() to replace open(), and that the direct use of file()
is not preferred... which surprised a lot of us, apparently including
the person who wrote those docs. :) )
Are there any variants of the "open" commmand that allow location (drive and directory) of the file to be specified as well, for example, if I wanted to save the file as "D:\binaries\t rash.gif" instead of the default location?
As a matter of fact, the standard open() will handle that just fine --
it accepts a pathname, rather than just a filename, so you can feed it
an absolute path like your example or a relative path (e.g.,
subdir\trash.gi f or ..\siblingdir\t rash.gif) and it'll be perfectly
happy. The one catch is that, on Windows, the directory separator
conflicts with the escape character, '\'. So when typing path literals,
be sure to either always use double backslashes (
"d:\\binaries\\ trash.gif" ) or 'raw' strings ( r"d:\binaries\t rash.gif"
) so that your \trash doesnt become [tab]rash. Or better yet, use
os.path.join() (and the other os.path functions) to construct your paths.
Jeff Shannon
Technician/Programmer
Credit International
On Thu, 16 Sep 2004 19:59:17 -0700, Jeff Shannon <je**@ccvcorp.c om>
declaimed the following in comp.lang.pytho n: happy. The one catch is that, on Windows, the directory separator conflicts with the escape character, '\'. So when typing path literals, be sure to either always use double backslashes ( "d:\\binaries\\ trash.gif" ) or 'raw' strings ( r"d:\binaries\t rash.gif" ) so that your \trash doesnt become [tab]rash. Or better yet, use os.path.join() (and the other os.path functions) to construct your paths.
When used in direct programming calls (like open() ), Windows
seems happy with "/"s. It is only in things like os.system() where the
string is passed to an external command interpreter that you MUST use
the "\"s.
-- =============== =============== =============== =============== == < wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG < wu******@dm.net | Bestiaria Support Staff < =============== =============== =============== =============== == < Home Page: <http://www.dm.net/~wulfraed/> < Overflow Page: <http://wlfraed.home.ne tcom.com/> <
Jeff Shannon wrote: Radioactive Man wrote: Are there any variants of the "open" commmand that allow location (drive and directory) of the file to be specified as well, for example, if I wanted to save the file as "D:\binaries\tr ash.gif" instead of the default location?
As a matter of fact, the standard open() will handle that just fine -- it accepts a pathname, rather than just a filename, so you can feed it an absolute path like your example or a relative path ...
But note that the directories have to exist already. If they don't,
you need to use something like os.makedirs() to get 'em.
-Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: S P Arif Sahari Wibowo |
last post by:
Hi!
I am thinking to have a client-side script doing processing on file
downloading, basically the script will process a downloaded file from the
server before it received by the user. For example, the weboage will have
a link to download file A, but the one stored in the server is not exactly
file A, but some transformation of it. If the user click the link, it
activate the script which will actually load the file from the server,...
|
by: Kevin Muenzler, WB5RUE |
last post by:
How do I force a browser to download a file instead of displaying it? In
other words I have a page with MP3 and WMA files on it and I would like for
the visitor to download the file instead of play it without having to
right-click and save.
How can I force the browser to pop up the "save file as" dialog box instead
of playing it? I know that I can encapsulate it in a zip file which will
download and open WinZip.
Thanks
|
by: mizi |
last post by:
I am writing an ASP page for downloading some files, such as jpg, doc
which are known MIME type. I want to force user save these files through
a "file download" dialog instead of open them on the IE by default. I
search the Internet and found the best way to do it is by using stream.
The following is my code for the download.asp. There are 2 problems, one
is when I use firefox and click the link to download.asp, I found the
system become...
|
by: clintonG |
last post by:
To all Microsoft partners and customers who have been unable to download
recently or access ASP.NET documentation from the msdn2 website and for all
of those customers who have been lied to and misled by some of the sleazy
MVPs and the lying cockroaches that Microsoft has working for the company...
Microsoft has serious problems with their servers and websites. The entire
MSDN server farm and all download resources MSDN manages has been...
|
by: mike |
last post by:
I help manage a large web site, one that has over
600 html pages... It's a reference site for ham radio
folks and as an example, one page indexes over
1.8 gb of on-line PDF documents.
The site is structured as an upside-down tree, and
(if I remember correctly) never more than 4 levels.
The site basically grew (like the creeping black blob) ...
all the pages were created in Notepad over the last
| |
by: michael.buonomo |
last post by:
We have been using the Google recommended python script for about a
year. We recently realized that the script was not crawling our sites
url's, but just our folders which reside on the server. The python
script seems to be designed for 'non database' sites, not a site which
is using .asp, and has dynamic pages.
We are an ecommerce site. What are other ecommerce sites using to
create an xml file?
Are they using the python script?
|
by: Bob |
last post by:
Hello everyone !!!
I have a very neat script to download files to the server, the problem is
that it uploads all kind of files, txt, exe, zip,
you name it. I have been trying to add some code but still can't get it to
work. What I would like the script to do is only to allow the jpg, jpeg,
bmp, gif files to be downloaded. Can anyone can give me a hand?
Thanks in Advance, Bob.
This is the script. >>>>>>>>>>>>>>>>>>>>>
<form name="upload"...
|
by: aRTx |
last post by:
I have try a couple of time but does not work for me
My files everytime are sortet by NAME.
I want to Sort my files by Date-desc.
Can anyone help me to do it?
The Script
<?
/*
ORIGJINALI
|
by: Tim Jones |
last post by:
I have a web site where we offer MP3 downloads (yes, they are
legal!). I've written a PHP script using readfile() (or fpassthru())
that sends the file using HTTP headers (via various header()
directives). The script launches the download fine and the download
proceeds normally. However, after 20MB - 35MB of the download
completes, the download suddenly completes even though the entire file
wasn't download. (The download does not fail.)...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |