hydromechanic
2021-08-26 09:47
采纳率: 100%
浏览 126
已结题

requests.exceptions.InvalidURL: Failed to parse: <Response [200]>


import tkinter as tk
from tkinter import *
import tkinter.messagebox
import requests
import urllib.request

windows = tk.Tk()
windows.title("Harryの音乐下载器(试用版)")
windows.geometry("500x300")  # 界面大小
windows.iconbitmap("netease.ico")

input_space = tkinter.Entry(windows,
                            fg="black",
                            bg="white",
                            width=50,
                            font=('微软雅黑', 10, 'bold'),
                            show="")
input_space.place(relx=0.3, rely=0.3,
                  anchor="center")
input_space.pack()


def convert():
    url = input_space.get()
    t.insert("insert", "http://music.163.com/song/media/outer/url?id" + url.split("/song?id")[1] + ".mp3")
    tk.messagebox.showinfo("提醒!", "转换完成DA☆ZE\n全选复制到浏览器就好了DA☆ZE")


def save_file():
    url = input_space.get()
    url_get = requests.get("http://music.163.com/song/media/outer/url?id" + url.split("/song?id")[1] + ".mp3", )
    file_path = "C:\\Users\\Harry\\Desktop"
    tk.messagebox.showinfo("提醒!", "尝试下载中...")
    r = requests.get(str(url_get))
    headers = r.headers
    html = requests.get(str(url_get), headers=headers)
    urllib.request.urlretrieve(str(html), file_path)
    try:
        if r.status_code == requests.codes.ok:
            pass
    except ValueError:
        tk.messagebox.showinfo("Error!", "请检查一下自己的url拼写!")


save_button = tkinter.Button(windows, text="神奇的下载按钮~",
                             fg="black",
                             bg="white",
                             relief=RIDGE,
                             font=('微软雅黑', 12, 'bold'),
                             command=save_file)

save_button.place(relx=0.8, rely=0.4)
save_button.pack()

convert_button = tkinter.Button(windows, text="神奇的转换按钮~",
                                fg="black",
                                bg="white",
                                relief=RIDGE,
                                font=('微软雅黑', 12, 'bold'),
                                command=convert)
convert_button.place(relx=0.3, rely=0.4, )
convert_button.pack()

t = Text(windows, width=50, font='微软雅黑')
t.pack()

windows.mainloop()

这个为什么报错了啊

  • 收藏

2条回答 默认 最新

  • CSDN专家-黄老师 2021-08-26 10:05
    已采纳

    url_get = requests.get(" http://music.163.com/song/media/outer/url?id%22 + url.split("/song?id")[1] + ".mp3", )和r = requests.get(str(url_get))
    冲突了,,第二个r = requests.get(str(url_get))的str(url_get)是一个对象,不是网址

    1 打赏 评论
  • CSDN专家-showbo 2021-08-26 10:52

    获得MP3地址要保存直接下载保存就行了,

    1 2 打赏 评论

相关推荐 更多相似问题