[英]Python 3.4.3 save image from url to file using urllib
I tried to make a python program that would allow me to download a jpg file from a website. 我试图制作一个Python程序,该程序可以让我从网站下载jpg文件。
Why I'm doing this is really for no reason at all, I just wanted to try it for fun. 我这么做的原因根本没有任何原因,我只是想尝试一下而已。
Anyways, here is the code: 无论如何,这是代码:
import urllib
a = 1
while a == 1:
urllib.urlretrieve("http://lemerg.com/data/wallpapers/38/957049.jpg","D:\\Users\\Elias\\Desktop\\FolderName-957049.jpg")
(You may have to properly tab it in, it wouldn't let me here) (您可能需要正确地输入它,否则不会让我在这里)
So basically what I want it to do is to repeatedly download the same file until I close the program. 因此,基本上,我要执行的操作是重复下载相同的文件,直到关闭程序为止。 Just don't ask why.
只是不要问为什么。
The error code I get is: Traceback (most recent call last): urllib.urlretrieve(" http://lemerg.com/data/wallpapers/38/957049.jpg ","D:\\Users\\Elias\\Desktop\\FolderName-957049.jpg") AttributeError: 'module' object has no attribute 'urlretrieve' 我得到的错误代码是:追溯(最近一次通话):urllib.urlretrieve(“ http://lemerg.com/data/wallpapers/38/957049.jpg ”,“ D:\\ Users \\ Elias \\ Desktop \\ FolderName -957049.jpg”)AttributeError:“模块”对象没有属性“ urlretrieve”
urlretrieve()
in Python3 is in the urllib.request
module. urlretrieve()
位于urllib.request
模块中。 Do this: 做这个:
from urllib import request
a = 1
while a == 1:
request.urlretrieve("http://lemerg.com/data/wallpapers/38/957049.jpg","D:\\Users\\Elias\\Desktop\\FolderName-957049.jpg")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.