且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

urllib.urlretrieve 文件 python 3.3

更新时间:2022-10-20 15:44:17

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

>>>从 urllib 导入 urlretrieve回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中导入错误:无法导入名称 urlretrieve>>>>>>从 urllib.request 导入 urlretrieve>>>网址检索<函数 urlretrieve at 0x023C2390>>>>

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

Simple urllib.urlretrieve in 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).

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.

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?

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.

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.

In Python 3.x, the urlretrieve function is located in the urllib.request module:

>>> 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>
>>>