本帖最后由 reol_233 于 2019-5-5 11:59 编辑
如有问题,望指正
界面
[Python] 纯文本查看 复制代码 import requests
import re
from urllib import request
import tkinter as tk
import tkinter.messagebox
root = tk.Tk()
root.geometry('400x150')
root.title('获取b站封面')
url_get = tk.Entry(root, width=30)
url_get.place(x=100, y=40)
def fetch():
url = make_url()
if url:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"}
res = requests.get(url, headers=headers)
text = res.text
url_bg = re.findall(r'itemprop="image" content="(.*?)"/>', text)[0]
av_id = url.split('/')[4]
# print(av_id[2::])
request.urlretrieve(url_bg, av_id+'.png')
tkinter.messagebox.showinfo(title='少女祈祷中', message='保存成功')
def make_url():
var = url_get.get()
if re.match('https://www.bilibili.com/video/av', var):
return var
elif re.match('av', var):
return 'https://www.bilibili.com/video/' + var
elif var.isdigit():
return 'https://www.bilibili.com/video/av' + var
else:
tkinter.messagebox.showerror(title='大沙比', message='请输入正确的av号或链接')
return None
lab1 = tk.Label(root, text='请输入av号或者链接:')
lab1.place(x=100, y=20)
bt1 = tk.Button(root, text='确定', command=fetch)
bt1.place(x=150, y=70)
bt2 = tk.Button(root, text='退出', command=root.destroy)
bt2.place(x=210, y=70)
root.mainloop()
|