重感情的生姜 · 琉璃璇玑和昊辰订婚 ...· 4 月前 · |
怕老婆的火柴 · 警察警服与海军军服,最相似的时代,只有看帽徽 ...· 4 月前 · |
热心肠的长颈鹿 · 地下管线三维自动建模软件MagicPipe3 ...· 9 月前 · |
文质彬彬的红豆 · 聊聊学英语这件糟心的事 - 知乎· 1 年前 · |
深情的针织衫 · 陈琳-全部作品在线阅读-微信读书· 1 年前 · |
有人能破解我的密码吗?我也太乞丐了,如果你告诉我如何更有效率地做这件事,而不必为每种文件类型创建不同的函数,我会很高兴的。
(你可以把这段代码看作是上世纪90年代一个研究机构的终端,当时互联网还不太好,所以我想放慢下载速度,让人感觉它真的是90年代了。)
import wget
x = ""
def png_download():
print("this code is can only download png btw")
time.sleep(1)
print("enter url")
command = input('Terminal: ').strip()
command = x
# file url
remote_url = ("'"+x+"'")
local_file = 'file.png'
# aksiyon
wget.download(remote_url, local_file)
while True: #Terminal
print ("")
command = input('Terminal: ').strip()
if command == 'Download_png':
png_download()
else:
print("")
如果运行代码并输入url,就会发生这样的情况:
File "c:\Dosyalar\Yazılım\Python\Foundation Terminal 14\Terminal Downloader Extension ENG .py", line 28, in <module>
png_download()
File "c:\Dosyalar\Yazılım\Python\Foundation Terminal 14\Terminal Downloader Extension ENG .py", line 22, in png_download
wget.download(remote_url, local_file)
File "C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\wget.py", line 526, in download
(tmpfile, headers) = ulib.urlretrieve(binurl, tmpfile, callback)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 239, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 501, in open
req = Request(fullurl, data)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 320, in __init__
self.full_url = url
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 346, in full_url
self._parse()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0\lib\urllib\request.py", line 375, in _parse
raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: '%27%27' ```
发布于 2022-01-17 08:31:43
ValueError:未知url类型:'%27%27‘
27
是
'
字符的(十六进制)代码,这意味着您为
wget.download
提供的第一个参数是
''
,这显然不是合法地址。这是因为您将x设置为空字符串(
x = ""
),但没有对其进行任何更改,然后执行了。
remote_url = ("'"+x+"'")
和
wget.download(remote_url, local_file)
假设用户总是提供合法的URL,那么您的
png_download
应该修改为
def png_download():
print("this code is can only download png btw")
time.sleep(1)
print("enter url")
remote_url = input('Terminal: ').strip()
local_file = 'file.png'
# aksiyon
wget.download(remote_url, local_file)
发布于 2022-01-16 18:35:27
用Python下载文件的方法要简单得多:
import os
import requests
def download_file_to(file_url, destination_folder, new_file_name=None):
if new_file_name:
file_name = new_file_name
怕老婆的火柴 · 警察警服与海军军服,最相似的时代,只有看帽徽一个办法 4 月前 |
文质彬彬的红豆 · 聊聊学英语这件糟心的事 - 知乎 1 年前 |
深情的针织衫 · 陈琳-全部作品在线阅读-微信读书 1 年前 |