使用python将文件下载到特定文件夹 [英] Download a file to a specific folder with python
问题描述
我正在尝试将特定文件下载到硬盘上的特定文件夹.我正在使用 IronPython 2.7 和 urllib
模块.
I am trying to download a particular file to a specific folder on my hardisk. I am using IronPython 2.7 and urllib
module.
我尝试使用以下代码下载文件:
I tried downloading the file with the following code:
import urllib
response = urllib.urlretrieve(someURL, 'C:/someFolder')
html = response.read()
response.close()
但是当运行上层代码时,我收到以下错误消息:
But when upper code is ran, I get the following error message:
Runtime error (IOException): Access to the path 'D:\someFolder' is denied.
Traceback:
line 91, in urlretrieve, "C:\Program Files\IronPython\Lib\urllib.py"
line 9, in script
line 241, in retrieve, "C:\Program Files\IronPython\Lib\urllib.py"
我尝试输入someFolder"的属性,发现只读"被选中.我取消选中它,单击应用"和确定".但是当我再次回来时,再次选中只读".无论我取消选中并确认多少次,相同文件夹"仍然保持只读".这就是我收到上层错误消息的原因吗?
I tried entering the Attributes of my "someFolder", and found out the "Read-only" is checked. I unchecked it, clicked "Apply" and "Ok". But when I come back again, "Read-only" is checked again. No matter how many times I uncheck it and confirm, it the "sameFolder" still remains "Read-only". Is this the reason why I am getting the upper error message?
热修复它?我尝试将someFolder"移动到其他分区,但仍然出于某种原因我无法取消选中只读"属性(我可以,但它只是不断回来).
Hot to fix it? I tried moving the "someFolder" to other partitions, but still for some reason I can not uncheck the "Read-only" attribute (I can, but it just keeps coming back).
感谢您的回复.
我忘了说我使用的是 Windows XP 32 位.
I forgot to say that I use Windows XP 32 bit.
我检查了someFolder"是否可写,确实如此.以下代码:
I checked if "someFolder" is writable and it is. The following code:
print os.access("C:/someFolder", os.W_OK)
返回:True
.
推荐答案
你可能想改用这个:
import os
import urllib
fullfilename = os.path.join('C:/somedir', 'test.html')
urllib.urlretrieve("http://www.google.com", fullfilename)
这篇关于使用python将文件下载到特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!