urllib.urlretrieve 文件 python 3.3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21171718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:12:45  来源:igfitidea点击:

urllib.urlretrieve file python 3.3

pythontkinter

提问by confused

I know I have seen the answer somewhere a couple of weeks ago but I can't find it now.

我知道几周前我在某处看到了答案,但现在找不到了。

Simple urllib.urlretrievein Python 3.3. How do you do it? I'm trying to download an mp4/html(Page does not exist) scenario, either the page if it does not exist or the mp4 if it does(I can delete the file if the file size is to small or keep it otherwise).

urllib.urlretrieve在 Python 3.3 中很简单。你怎么做呢?我正在尝试下载 mp4/html(页面不存在)方案,如果页面不存在,则为 mp4(如果文件大小不存在,我可以删除文件,否则保留) .

The code I have runs fine and does exactly what I want it to do in 2.7, but it doesn't work in 3.3.

我的代码运行良好,并且在 2.7 中完全按照我的意愿执行,但在 3.3 中不起作用。

I'm dealing with both giving me headaches, Tkinter and urllib between the two version of Python. Tkinter works fine in 3.3, but urllib doesn't and urllib works fine in 2.7 but Tkinter doesn't. How do I get this to download correctly in 3.3?

我正在处理两个让我头疼的问题,Tkinter 和 urllib 在两个版本的 Python 之间。Tkinter 在 3.3 中可以正常工作,但 urllib 不能,urllib 在 2.7 中可以正常工作,但 Tkinter 不能。如何在 3.3 中正确下载?

I know 3.3 has changed the urllib but I can't find what I saw a week or two ago to guide me in the correct direction.

我知道 3.3 更改了 urllib,但我找不到一两周前看到的内容来指导我朝着正确的方向前进。

2.7 does pretty much nothing when I add the Tkinter change over in and 3.3 just comes up and gives me urllib doesn't have an attribute 'urlretrieve;. I prefer 3.3.

当我添加 Tkinter 更改时,2.7 几乎没有任何作用,而 3.3 刚刚出现并给我 urllib 没有属性“urlretrieve;”。我更喜欢3.3。

回答by confused

In Python 3.x, the urlretrievefunction is located in the urllib.requestmodule:

在 Python 3.x 中,该urlretrieve函数位于urllib.request模块中:

>>> from urllib import urlretrieve
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name urlretrieve
>>>
>>> from urllib.request import urlretrieve
>>> urlretrieve
<function urlretrieve at 0x023C2390>
>>>